Skip to content

Commit

Permalink
feat(transport): add from_listener for TcpIncoming (#1093)
Browse files Browse the repository at this point in the history
  • Loading branch information
w41ter authored Oct 3, 2022
1 parent 3663faf commit 0b03b30
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tonic/src/transport/server/incoming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>(
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0b03b30

Please sign in to comment.