diff --git a/ChangeLog.txt b/ChangeLog.txt
index 8010c90c8a..05110cfc65 100644
--- a/ChangeLog.txt
+++ b/ChangeLog.txt
@@ -60,6 +60,8 @@ Broker:
- Fix upgrade_outgoing_qos for retained message. Closes #534.
- Fix CONNACK message not being sent for unauthorised connect on websockets.
Closes #8.
+- Add set_tcp_nodelay option to allow Nagle's algorithm to be disabled on
+ client sockets. Closes #433.
Client library:
- Outgoing messages with QoS>1 are no longer retried after a timeout period.
diff --git a/man/mosquitto.conf.5.xml b/man/mosquitto.conf.5.xml
index 829757f073..36c829b196 100644
--- a/man/mosquitto.conf.5.xml
+++ b/man/mosquitto.conf.5.xml
@@ -585,6 +585,17 @@
Reloaded on reload signal.
+
+ [ true | false ]
+
+ If set to true, the TCP_NODELAY option will be set on
+ client sockets to disable Nagle's algorithm. This
+ has the effect of reducing latency of some messages
+ at potentially increasing the number of TCP packets
+ being sent. Defaults to false.
+ Reloaded on reload signal.
+
+
seconds
diff --git a/mosquitto.conf b/mosquitto.conf
index b30c2cf852..b383c0a99a 100644
--- a/mosquitto.conf
+++ b/mosquitto.conf
@@ -131,6 +131,11 @@
# This is a non-standard option explicitly disallowed by the spec.
#upgrade_outgoing_qos false
+# Disable Nagle's algorithm on client sockets. This has the effect of reducing
+# latency of individual messages at the potential cost of increasing the number
+# of packets being sent.
+#set_tcp_nodelay false
+
# =================================================================
# Default listener
# =================================================================
diff --git a/src/conf.c b/src/conf.c
index 734ab80ad2..44207d43e1 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -188,6 +188,7 @@ static void config__init_reload(struct mosquitto__config *config)
mosquitto__free(config->psk_file);
config->psk_file = NULL;
config->queue_qos0_messages = false;
+ config->set_tcp_nodelay = false;
config->sys_interval = 10;
config->upgrade_outgoing_qos = false;
if(config->auth_plugins){
@@ -1575,6 +1576,8 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, const
#else
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Bridge support not available.");
#endif
+ }else if(!strcmp(token, "set_tcp_nodelay")){
+ if(conf__parse_bool(&token, "set_tcp_nodelay", &config->set_tcp_nodelay, saveptr)) return MOSQ_ERR_INVAL;
}else if(!strcmp(token, "start_type")){
#ifdef WITH_BRIDGE
if(reload) continue; // FIXME
diff --git a/src/mosquitto_broker_internal.h b/src/mosquitto_broker_internal.h
index 77a10fa491..92fac93b7b 100644
--- a/src/mosquitto_broker_internal.h
+++ b/src/mosquitto_broker_internal.h
@@ -210,6 +210,7 @@ struct mosquitto__config {
char *pid_file;
char *psk_file;
bool queue_qos0_messages;
+ bool set_tcp_nodelay;
int sys_interval;
bool upgrade_outgoing_qos;
char *user;
diff --git a/src/net.c b/src/net.c
index e201f6b685..a0f90b81b8 100644
--- a/src/net.c
+++ b/src/net.c
@@ -21,6 +21,7 @@ and the Eclipse Distribution License is available at
#include
#include
#include
+#include
#else
#include
#include
@@ -120,6 +121,12 @@ int net__socket_accept(struct mosquitto_db *db, mosq_sock_t listensock)
return -1;
}
#endif
+
+ if(db->config->set_tcp_nodelay){
+ int flag = 1;
+ setsockopt(new_sock, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(int));
+ }
+
new_context = context__init(db, new_sock);
if(!new_context){
COMPAT_CLOSE(new_sock);