Add a fast path to TcpListener::accept

This commit is contained in:
Alex Crichton 2017-01-23 20:12:01 -08:00
parent b22b797278
commit c9d0fe59dd

View File

@ -78,6 +78,15 @@ impl TcpListener {
return Err(e)
},
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 remote = self.io.remote().clone();
remote.spawn(move |handle| {