Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/tls_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub struct TlsListener<State> {
connection: TcpConnection,
config: TlsListenerConfig,
server: Option<Server<State>>,
tcp_nodelay: Option<bool>,
tcp_ttl: Option<u32>,
}

impl<State> Debug for TlsListener<State> {
Expand All @@ -47,11 +49,13 @@ impl<State> Debug for TlsListener<State> {
}

impl<State> TlsListener<State> {
pub(crate) fn new(connection: TcpConnection, config: TlsListenerConfig) -> Self {
pub(crate) fn new(connection: TcpConnection, config: TlsListenerConfig, tcp_nodelay: Option<bool>, tcp_ttl: Option<u32>) -> Self {
Self {
connection,
config,
server: None,
tcp_nodelay,
tcp_ttl,
}
}
/// The primary entrypoint to create a TlsListener. See
Expand Down Expand Up @@ -203,7 +207,17 @@ impl<State: Clone + Send + Sync + 'static> Listener<State> for TlsListener<State
continue;
}

Ok(stream) => handle_tls(server.clone(), stream, acceptor.clone()),
Ok(stream) => {
if let Some(nodelay) = self.tcp_nodelay {
stream.set_nodelay(nodelay)?;
}

if let Some(ttl) = self.tcp_ttl {
stream.set_ttl(ttl)?;
}

handle_tls(server.clone(), stream, acceptor.clone())
}
};
}
Ok(())
Expand Down
20 changes: 19 additions & 1 deletion src/tls_listener_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub struct TlsListenerBuilder<State> {
tls_acceptor: Option<Arc<dyn CustomTlsAcceptor>>,
tcp: Option<TcpListener>,
addrs: Option<Vec<SocketAddr>>,
tcp_nodelay: Option<bool>,
tcp_ttl: Option<u32>,
_state: PhantomData<State>,
}

Expand All @@ -54,6 +56,8 @@ impl<State> Default for TlsListenerBuilder<State> {
tls_acceptor: None,
tcp: None,
addrs: None,
tcp_nodelay: None,
tcp_ttl: None,
_state: PhantomData,
}
}
Expand Down Expand Up @@ -148,6 +152,18 @@ impl<State> TlsListenerBuilder<State> {
self
}

/// Provides a TCP_NODELAY option for this tls listener.
pub fn nodelay(mut self, nodelay: bool) -> Self {
self.tcp_nodelay = Some(nodelay);
self
}

/// Provides a TTL option for this tls listener.
pub fn ttl(mut self, ttl: u32) -> Self {
self.tcp_ttl = Some(ttl);
self
}

/// finishes building a TlsListener from this TlsListenerBuilder.
///
/// # Errors
Expand All @@ -168,6 +184,8 @@ impl<State> TlsListenerBuilder<State> {
tls_acceptor,
tcp,
addrs,
tcp_nodelay,
tcp_ttl,
..
} = self;

Expand All @@ -194,6 +212,6 @@ impl<State> TlsListenerBuilder<State> {
}
};

Ok(TlsListener::new(connection, config))
Ok(TlsListener::new(connection, config, tcp_nodelay, tcp_ttl))
}
}