Skip to content

Commit ae009b5

Browse files
committed
Move TCP_NODELAY and TTL options to TlsListenerBuilder.
1 parent 83a1948 commit ae009b5

File tree

2 files changed

+23
-31
lines changed

2 files changed

+23
-31
lines changed

src/tls_listener.rs

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ impl<State> Debug for TlsListener<State> {
4949
}
5050

5151
impl<State> TlsListener<State> {
52-
pub(crate) fn new(connection: TcpConnection, config: TlsListenerConfig) -> Self {
52+
pub(crate) fn new(connection: TcpConnection, config: TlsListenerConfig, tcp_nodelay: Option<bool>, tcp_ttl: Option<u32>) -> Self {
5353
Self {
5454
connection,
5555
config,
5656
server: None,
57-
tcp_nodelay: None,
58-
tcp_ttl: None,
57+
tcp_nodelay,
58+
tcp_ttl,
5959
}
6060
}
6161
/// The primary entrypoint to create a TlsListener. See
@@ -129,32 +129,6 @@ impl<State> TlsListener<State> {
129129
}
130130
Ok(())
131131
}
132-
133-
/// Set TCP_NODELAY socket option.
134-
pub fn set_nodelay(&mut self, nodelay: bool) {
135-
self.tcp_nodelay = Some(nodelay);
136-
}
137-
138-
/// Get TCP_NODELAY socket option.
139-
pub fn nodelay(&self) -> Option<bool> {
140-
self.tcp_nodelay
141-
}
142-
143-
/// Set TCP_NODELAY socket option.
144-
pub fn with_nodelay(mut self, nodelay: bool) -> Self {
145-
self.set_nodelay(nodelay);
146-
self
147-
}
148-
149-
/// Set TTL option.
150-
pub fn set_ttl(&mut self, ttl: u32) {
151-
self.tcp_ttl = Some(ttl);
152-
}
153-
154-
/// Get TTL option.
155-
pub fn ttl(&self) -> Option<u32> {
156-
self.tcp_ttl
157-
}
158132
}
159133

160134
fn handle_tls<State: Clone + Send + Sync + 'static>(
@@ -243,7 +217,7 @@ impl<State: Clone + Send + Sync + 'static> Listener<State> for TlsListener<State
243217
}
244218

245219
handle_tls(server.clone(), stream, acceptor.clone())
246-
},
220+
}
247221
};
248222
}
249223
Ok(())

src/tls_listener_builder.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ pub struct TlsListenerBuilder<State> {
4242
tls_acceptor: Option<Arc<dyn CustomTlsAcceptor>>,
4343
tcp: Option<TcpListener>,
4444
addrs: Option<Vec<SocketAddr>>,
45+
tcp_nodelay: Option<bool>,
46+
tcp_ttl: Option<u32>,
4547
_state: PhantomData<State>,
4648
}
4749

@@ -54,6 +56,8 @@ impl<State> Default for TlsListenerBuilder<State> {
5456
tls_acceptor: None,
5557
tcp: None,
5658
addrs: None,
59+
tcp_nodelay: None,
60+
tcp_ttl: None,
5761
_state: PhantomData,
5862
}
5963
}
@@ -148,6 +152,18 @@ impl<State> TlsListenerBuilder<State> {
148152
self
149153
}
150154

155+
/// Provides a TCP_NODELAY option for this tls listener.
156+
pub fn nodelay(mut self, nodelay: bool) -> Self {
157+
self.tcp_nodelay = Some(nodelay);
158+
self
159+
}
160+
161+
/// Provides a TTL option for this tls listener.
162+
pub fn ttl(mut self, ttl: u32) -> Self {
163+
self.tcp_ttl = Some(ttl);
164+
self
165+
}
166+
151167
/// finishes building a TlsListener from this TlsListenerBuilder.
152168
///
153169
/// # Errors
@@ -168,6 +184,8 @@ impl<State> TlsListenerBuilder<State> {
168184
tls_acceptor,
169185
tcp,
170186
addrs,
187+
tcp_nodelay,
188+
tcp_ttl,
171189
..
172190
} = self;
173191

@@ -194,6 +212,6 @@ impl<State> TlsListenerBuilder<State> {
194212
}
195213
};
196214

197-
Ok(TlsListener::new(connection, config))
215+
Ok(TlsListener::new(connection, config, tcp_nodelay, tcp_ttl))
198216
}
199217
}

0 commit comments

Comments
 (0)