Skip to content

Commit

Permalink
feat(server): add AddrIncoming::from_listener constructor (hyperium…
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo authored and roman-kashitsyn committed Apr 14, 2021
1 parent 17f5426 commit 82481b6
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/server/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ impl AddrIncoming {

pub(super) fn from_std(std_listener: StdTcpListener) -> crate::Result<Self> {
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<Self> {
AddrIncoming::new(addr)
}

/// Creates a new `AddrIncoming` from an existing `tokio::net::TcpListener`.
pub fn from_listener(listener: TcpListener) -> crate::Result<Self> {
let addr = listener.local_addr().map_err(crate::Error::new_listen)?;
Ok(AddrIncoming {
listener,
Expand All @@ -42,11 +52,6 @@ impl AddrIncoming {
})
}

/// Creates a new `AddrIncoming` binding to provided socket address.
pub fn bind(addr: &SocketAddr) -> crate::Result<Self> {
AddrIncoming::new(addr)
}

/// Get the local address bound to this listener.
pub fn local_addr(&self) -> SocketAddr {
self.addr
Expand Down

0 comments on commit 82481b6

Please sign in to comment.