feat(server): add Server::from_tcp constructor

Adds a constructor to build a `Server` from an `std::net::TcpListener`.

Closes #1602
This commit is contained in:
Yoshua Wuyts
2018-08-08 20:13:07 +02:00
committed by Sean McArthur
parent 6e8417e08f
commit bb4c5e24c8
2 changed files with 28 additions and 3 deletions

View File

@@ -44,6 +44,20 @@ impl AddrIncoming {
})
}
pub(super) fn from_tcp(std_listener: StdTcpListener, handle: &Handle) -> ::Result<Self>{
let listener = TcpListener::from_std(std_listener, &handle)
.map_err(::Error::new_listen)?;
let addr = listener.local_addr().map_err(::Error::new_listen)?;
Ok(AddrIncoming {
listener,
addr: addr,
sleep_on_errors: true,
tcp_keepalive_timeout: None,
tcp_nodelay: false,
timeout: None,
})
}
/// Get the local address bound to this listener.
pub fn local_addr(&self) -> SocketAddr {
self.addr