diff --git a/src/server/mod.rs b/src/server/mod.rs index fa89d7c8d0..95ce3aee5b 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -121,13 +121,10 @@ impl Server { } /// Create a new instance from a `std::net::TcpListener` instance. - pub fn from_tcp( - listener: StdTcpListener, - ) -> Result, ::Error> { + pub fn from_tcp(listener: StdTcpListener) -> Result, ::Error> { let handle = tokio_reactor::Handle::current(); - let incoming = AddrIncoming::from_tcp(listener, &handle) - .map_err(|err| ::Error::new_listen(err))?; - Ok(Self::builder(incoming)) + AddrIncoming::from_std(listener, &handle) + .map(Server::builder) } } diff --git a/src/server/tcp.rs b/src/server/tcp.rs index e54efd5209..a703acfef7 100644 --- a/src/server/tcp.rs +++ b/src/server/tcp.rs @@ -22,29 +22,19 @@ pub struct AddrIncoming { } impl AddrIncoming { - pub(super) fn new(addr: &SocketAddr, handle: Option<&Handle>) -> ::Result { - let listener = if let Some(handle) = handle { - let std_listener = StdTcpListener::bind(addr) + pub(super) fn new(addr: &SocketAddr, handle: Option<&Handle>) -> ::Result { + let std_listener = StdTcpListener::bind(addr) .map_err(::Error::new_listen)?; - TcpListener::from_std(std_listener, handle) - .map_err(::Error::new_listen)? - } else { - TcpListener::bind(addr).map_err(::Error::new_listen)? - }; - - let addr = listener.local_addr().map_err(::Error::new_listen)?; - Ok(AddrIncoming { - addr: addr, - listener: listener, - sleep_on_errors: true, - tcp_keepalive_timeout: None, - tcp_nodelay: false, - timeout: None, - }) + if let Some(handle) = handle { + AddrIncoming::from_std(std_listener, handle) + } else { + let handle = Handle::current(); + AddrIncoming::from_std(std_listener, &handle) + } } - pub(super) fn from_tcp(std_listener: StdTcpListener, handle: &Handle) -> ::Result{ + pub(super) fn from_std(std_listener: StdTcpListener, handle: &Handle) -> ::Result { let listener = TcpListener::from_std(std_listener, &handle) .map_err(::Error::new_listen)?; let addr = listener.local_addr().map_err(::Error::new_listen)?;