feat(transport): add from_listener for TcpIncoming (#1093)
This commit is contained in:
@@ -12,7 +12,10 @@ use std::{
|
|||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
use tokio::io::{AsyncRead, AsyncWrite};
|
use tokio::{
|
||||||
|
io::{AsyncRead, AsyncWrite},
|
||||||
|
net::TcpListener,
|
||||||
|
};
|
||||||
|
|
||||||
#[cfg(not(feature = "tls"))]
|
#[cfg(not(feature = "tls"))]
|
||||||
pub(crate) fn tcp_incoming<IO, IE, L>(
|
pub(crate) fn tcp_incoming<IO, IE, L>(
|
||||||
@@ -172,6 +175,18 @@ impl TcpIncoming {
|
|||||||
inner.set_keepalive(keepalive);
|
inner.set_keepalive(keepalive);
|
||||||
Ok(TcpIncoming { inner })
|
Ok(TcpIncoming { inner })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a new `TcpIncoming` from an existing `tokio::net::TcpListener`.
|
||||||
|
pub fn from_listener(
|
||||||
|
listener: TcpListener,
|
||||||
|
nodelay: bool,
|
||||||
|
keepalive: Option<Duration>,
|
||||||
|
) -> Result<Self, crate::Error> {
|
||||||
|
let mut inner = AddrIncoming::from_listener(listener)?;
|
||||||
|
inner.set_nodelay(nodelay);
|
||||||
|
inner.set_keepalive(keepalive);
|
||||||
|
Ok(TcpIncoming { inner })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Stream for TcpIncoming {
|
impl Stream for TcpIncoming {
|
||||||
|
|||||||
Reference in New Issue
Block a user