diff --git a/src/server/tcp.rs b/src/server/tcp.rs index 91afc40120..16a663719c 100644 --- a/src/server/tcp.rs +++ b/src/server/tcp.rs @@ -36,6 +36,16 @@ impl AddrIncoming { .set_nonblocking(true) .map_err(crate::Error::new_listen)?; let listener = TcpListener::from_std(std_listener).map_err(crate::Error::new_listen)?; + AddrIncoming::from_listener(listener) + } + + /// Creates a new `AddrIncoming` binding to provided socket address. + pub fn bind(addr: &SocketAddr) -> crate::Result { + AddrIncoming::new(addr) + } + + /// Creates a new `AddrIncoming` from an existing `tokio::net::TcpListener`. + pub fn from_listener(listener: TcpListener) -> crate::Result { let addr = listener.local_addr().map_err(crate::Error::new_listen)?; Ok(AddrIncoming { listener, @@ -47,11 +57,6 @@ impl AddrIncoming { }) } - /// Creates a new `AddrIncoming` binding to provided socket address. - pub fn bind(addr: &SocketAddr) -> crate::Result { - AddrIncoming::new(addr) - } - /// Get the local address bound to this listener. pub fn local_addr(&self) -> SocketAddr { self.addr