@@ -27,6 +27,8 @@ pub struct TlsListener<State> {
27
27
connection : TcpConnection ,
28
28
config : TlsListenerConfig ,
29
29
server : Option < Server < State > > ,
30
+ tcp_nodelay : Option < bool > ,
31
+ tcp_ttl : Option < u32 > ,
30
32
}
31
33
32
34
impl < State > Debug for TlsListener < State > {
@@ -52,6 +54,8 @@ impl<State> TlsListener<State> {
52
54
connection,
53
55
config,
54
56
server : None ,
57
+ tcp_nodelay : None ,
58
+ tcp_ttl : None ,
55
59
}
56
60
}
57
61
/// The primary entrypoint to create a TlsListener. See
@@ -125,6 +129,32 @@ impl<State> TlsListener<State> {
125
129
}
126
130
Ok ( ( ) )
127
131
}
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
+ }
128
158
}
129
159
130
160
fn handle_tls < State : Clone + Send + Sync + ' static > (
@@ -203,7 +233,17 @@ impl<State: Clone + Send + Sync + 'static> Listener<State> for TlsListener<State
203
233
continue ;
204
234
}
205
235
206
- Ok ( stream) => handle_tls ( server. clone ( ) , stream, acceptor. clone ( ) ) ,
236
+ Ok ( stream) => {
237
+ if let Some ( nodelay) = self . tcp_nodelay {
238
+ stream. set_nodelay ( nodelay) ?;
239
+ }
240
+
241
+ if let Some ( ttl) = self . tcp_ttl {
242
+ stream. set_ttl ( ttl) ?;
243
+ }
244
+
245
+ handle_tls ( server. clone ( ) , stream, acceptor. clone ( ) )
246
+ } ,
207
247
} ;
208
248
}
209
249
Ok ( ( ) )
0 commit comments