mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-29 00:00:11 +02:00
Add a fast path to TcpListener::accept
This commit is contained in:
@@ -78,6 +78,15 @@ impl TcpListener {
|
|||||||
return Err(e)
|
return Err(e)
|
||||||
},
|
},
|
||||||
Ok((sock, addr)) => {
|
Ok((sock, addr)) => {
|
||||||
|
// Fast path if we haven't left the event loop
|
||||||
|
if let Some(handle) = self.io.remote().handle() {
|
||||||
|
let io = try!(PollEvented::new(sock, &handle));
|
||||||
|
return Ok((TcpStream { io: io }, addr))
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we're off the event loop then send the socket back
|
||||||
|
// over there to get registered and then we'll get it back
|
||||||
|
// eventually.
|
||||||
let (tx, rx) = oneshot::channel();
|
let (tx, rx) = oneshot::channel();
|
||||||
let remote = self.io.remote().clone();
|
let remote = self.io.remote().clone();
|
||||||
remote.spawn(move |handle| {
|
remote.spawn(move |handle| {
|
||||||
|
|||||||
Reference in New Issue
Block a user