Skip to content

Commit 0b03b30

Browse files
authoredOct 3, 2022
feat(transport): add from_listener for TcpIncoming (#1093)
1 parent 3663faf commit 0b03b30

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed
 

‎tonic/src/transport/server/incoming.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ use std::{
1212
task::{Context, Poll},
1313
time::Duration,
1414
};
15-
use tokio::io::{AsyncRead, AsyncWrite};
15+
use tokio::{
16+
io::{AsyncRead, AsyncWrite},
17+
net::TcpListener,
18+
};
1619

1720
#[cfg(not(feature = "tls"))]
1821
pub(crate) fn tcp_incoming<IO, IE, L>(
@@ -172,6 +175,18 @@ impl TcpIncoming {
172175
inner.set_keepalive(keepalive);
173176
Ok(TcpIncoming { inner })
174177
}
178+
179+
/// Creates a new `TcpIncoming` from an existing `tokio::net::TcpListener`.
180+
pub fn from_listener(
181+
listener: TcpListener,
182+
nodelay: bool,
183+
keepalive: Option<Duration>,
184+
) -> Result<Self, crate::Error> {
185+
let mut inner = AddrIncoming::from_listener(listener)?;
186+
inner.set_nodelay(nodelay);
187+
inner.set_keepalive(keepalive);
188+
Ok(TcpIncoming { inner })
189+
}
175190
}
176191

177192
impl Stream for TcpIncoming {

0 commit comments

Comments
 (0)
Please sign in to comment.