@@ -35,13 +35,27 @@ use std::sync::Arc;
3535/// .config(rustls::ServerConfig::new(rustls::NoClientAuth::new()))
3636/// .finish();
3737/// ```
38+ ///
39+ /// ```rust
40+ /// # use tide_rustls::TlsListener;
41+ /// let listener = TlsListener::<()>::build()
42+ /// .addrs("localhost:4433")
43+ /// .cert("./tls/localhost-4433.cert")
44+ /// .key("./tls/localhost-4433.key")
45+ /// .tcp_ttl(60)
46+ /// .tcp_nodelay(true)
47+ /// .finish();
48+ /// ```
49+
3850pub struct TlsListenerBuilder < State > {
3951 key : Option < PathBuf > ,
4052 cert : Option < PathBuf > ,
4153 config : Option < ServerConfig > ,
4254 tls_acceptor : Option < Arc < dyn CustomTlsAcceptor > > ,
4355 tcp : Option < TcpListener > ,
4456 addrs : Option < Vec < SocketAddr > > ,
57+ tcp_nodelay : Option < bool > ,
58+ tcp_ttl : Option < u32 > ,
4559 _state : PhantomData < State > ,
4660}
4761
@@ -54,6 +68,8 @@ impl<State> Default for TlsListenerBuilder<State> {
5468 tls_acceptor : None ,
5569 tcp : None ,
5670 addrs : None ,
71+ tcp_nodelay : None ,
72+ tcp_ttl : None ,
5773 _state : PhantomData ,
5874 }
5975 }
@@ -82,6 +98,8 @@ impl<State> std::fmt::Debug for TlsListenerBuilder<State> {
8298 )
8399 . field ( "tcp" , & self . tcp )
84100 . field ( "addrs" , & self . addrs )
101+ . field ( "tcp_nodelay" , & self . tcp_nodelay )
102+ . field ( "tcp_ttl" , & self . tcp_ttl )
85103 . finish ( )
86104 }
87105}
@@ -148,6 +166,18 @@ impl<State> TlsListenerBuilder<State> {
148166 self
149167 }
150168
169+ /// Provides a TCP_NODELAY option for this tls listener.
170+ pub fn tcp_nodelay ( mut self , nodelay : bool ) -> Self {
171+ self . tcp_nodelay = Some ( nodelay) ;
172+ self
173+ }
174+
175+ /// Provides a TTL option for this tls listener, in seconds.
176+ pub fn tcp_ttl ( mut self , ttl : u32 ) -> Self {
177+ self . tcp_ttl = Some ( ttl) ;
178+ self
179+ }
180+
151181 /// finishes building a TlsListener from this TlsListenerBuilder.
152182 ///
153183 /// # Errors
@@ -168,6 +198,8 @@ impl<State> TlsListenerBuilder<State> {
168198 tls_acceptor,
169199 tcp,
170200 addrs,
201+ tcp_nodelay,
202+ tcp_ttl,
171203 ..
172204 } = self ;
173205
@@ -194,6 +226,6 @@ impl<State> TlsListenerBuilder<State> {
194226 }
195227 } ;
196228
197- Ok ( TlsListener :: new ( connection, config) )
229+ Ok ( TlsListener :: new ( connection, config, tcp_nodelay , tcp_ttl ) )
198230 }
199231}
0 commit comments