Skip to content

Commit

Permalink
add tcp_{nodelay,ttl} to Debug, example, tcp_ prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
jbr committed May 25, 2021
1 parent ae009b5 commit bdfa648
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! tide tls listener built on async-tls and rustls
//! tide tls listener built on async-rustls and rustls
//!
//!
//! # Example
//! ```rust
//! # use tide_rustls::TlsListener;
//! fn main() -> tide::Result<()> { async_std::task::block_on(async {
//! # fn main() -> tide::Result<()> { async_std::task::block_on(async {
//! let mut app = tide::new();
//! app.at("/").get(|_| async { Ok("Hello tls") });
//! # if false {
Expand All @@ -15,8 +15,7 @@
//! .key(std::env::var("TIDE_KEY_PATH").unwrap()),
//! )
//! .await?;
//! # }
//! # Ok(()) }) }
//! # } Ok(()) }) }
//! ```
#![forbid(unsafe_code, future_incompatible)]
#![deny(
Expand Down
9 changes: 8 additions & 1 deletion src/tls_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,19 @@ impl<State> Debug for TlsListener<State> {
&"None"
},
)
.field("tcp_ttl", &self.tcp_ttl)
.field("tcp_nodelay", &self.tcp_nodelay)
.finish()
}
}

impl<State> TlsListener<State> {
pub(crate) fn new(connection: TcpConnection, config: TlsListenerConfig, tcp_nodelay: Option<bool>, tcp_ttl: Option<u32>) -> Self {
pub(crate) fn new(
connection: TcpConnection,
config: TlsListenerConfig,
tcp_nodelay: Option<bool>,
tcp_ttl: Option<u32>,
) -> Self {
Self {
connection,
config,
Expand Down
20 changes: 17 additions & 3 deletions src/tls_listener_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ use std::sync::Arc;
/// .config(rustls::ServerConfig::new(rustls::NoClientAuth::new()))
/// .finish();
/// ```
///
/// ```rust
/// # use tide_rustls::TlsListener;
/// let listener = TlsListener::<()>::build()
/// .addrs("localhost:4433")
/// .cert("./tls/localhost-4433.cert")
/// .key("./tls/localhost-4433.key")
/// .tcp_ttl(60)
/// .tcp_nodelay(true)
/// .finish();
/// ```
pub struct TlsListenerBuilder<State> {
key: Option<PathBuf>,
cert: Option<PathBuf>,
Expand Down Expand Up @@ -86,6 +98,8 @@ impl<State> std::fmt::Debug for TlsListenerBuilder<State> {
)
.field("tcp", &self.tcp)
.field("addrs", &self.addrs)
.field("tcp_nodelay", &self.tcp_nodelay)
.field("tcp_ttl", &self.tcp_ttl)
.finish()
}
}
Expand Down Expand Up @@ -153,13 +167,13 @@ impl<State> TlsListenerBuilder<State> {
}

/// Provides a TCP_NODELAY option for this tls listener.
pub fn nodelay(mut self, nodelay: bool) -> Self {
pub fn tcp_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 {
/// Provides a TTL option for this tls listener, in seconds.
pub fn tcp_ttl(mut self, ttl: u32) -> Self {
self.tcp_ttl = Some(ttl);
self
}
Expand Down

0 comments on commit bdfa648

Please sign in to comment.