diff --git a/rumqttc/CHANGELOG.md b/rumqttc/CHANGELOG.md index 4353bf4a4..ce94f0052 100644 --- a/rumqttc/CHANGELOG.md +++ b/rumqttc/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * `ConnectionAborted` variant on `StateError` type to denote abrupt end to a connection * `set_session_expiry_interval` and `session_expiry_interval` methods on `MqttOptions`. * `Auth` packet as per MQTT5 standards +* Allow configuring the `nodelay` property of underlying TCP client with the `tcp_nodelay` field in `NetworkOptions` ### Changed diff --git a/rumqttc/src/eventloop.rs b/rumqttc/src/eventloop.rs index 1527c8603..f6730fe33 100644 --- a/rumqttc/src/eventloop.rs +++ b/rumqttc/src/eventloop.rs @@ -331,6 +331,8 @@ pub(crate) async fn socket_connect( SocketAddr::V6(_) => TcpSocket::new_v6()?, }; + socket.set_nodelay(network_options.tcp_nodelay)?; + if let Some(send_buff_size) = network_options.tcp_send_buffer_size { socket.set_send_buffer_size(send_buff_size).unwrap(); } diff --git a/rumqttc/src/lib.rs b/rumqttc/src/lib.rs index 29cad1a34..93887bb11 100644 --- a/rumqttc/src/lib.rs +++ b/rumqttc/src/lib.rs @@ -369,6 +369,7 @@ impl From for TlsConfiguration { pub struct NetworkOptions { tcp_send_buffer_size: Option, tcp_recv_buffer_size: Option, + tcp_nodelay: bool, conn_timeout: u64, #[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))] bind_device: Option, @@ -379,12 +380,17 @@ impl NetworkOptions { NetworkOptions { tcp_send_buffer_size: None, tcp_recv_buffer_size: None, + tcp_nodelay: false, conn_timeout: 5, #[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))] bind_device: None, } } + pub fn set_tcp_nodelay(&mut self, nodelay: bool) { + self.tcp_nodelay = nodelay; + } + pub fn set_tcp_send_buffer_size(&mut self, size: u32) { self.tcp_send_buffer_size = Some(size); }