feat(transport): add from_listener for TcpIncoming (#1093)
This commit is contained in:
@@ -12,7 +12,10 @@ use std::{
|
||||
task::{Context, Poll},
|
||||
time::Duration,
|
||||
};
|
||||
use tokio::io::{AsyncRead, AsyncWrite};
|
||||
use tokio::{
|
||||
io::{AsyncRead, AsyncWrite},
|
||||
net::TcpListener,
|
||||
};
|
||||
|
||||
#[cfg(not(feature = "tls"))]
|
||||
pub(crate) fn tcp_incoming<IO, IE, L>(
|
||||
@@ -172,6 +175,18 @@ impl TcpIncoming {
|
||||
inner.set_keepalive(keepalive);
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user