mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-09-22 16:15:05 +08:00
Add TCP_NODELAY support to lib and clients.
Closes #1526. Thanks to Felix Moessbauer.
This commit is contained in:
@@ -113,6 +113,7 @@ enum mosq_opt_t {
|
||||
MOSQ_OPT_TLS_ENGINE_KPASS_SHA1 = 8,
|
||||
MOSQ_OPT_TLS_OCSP_REQUIRED = 9,
|
||||
MOSQ_OPT_TLS_ALPN = 10,
|
||||
MOSQ_OPT_TCP_NODELAY = 11,
|
||||
};
|
||||
|
||||
|
||||
@@ -1432,6 +1433,12 @@ libmosq_EXPORT int mosquitto_opts_set(struct mosquitto *mosq, enum mosq_opt_t op
|
||||
* value - the option specific value.
|
||||
*
|
||||
* Options:
|
||||
* MOSQ_OPT_TCP_NODELAY -
|
||||
* Set to 1 to 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.
|
||||
* Defaults to 0, which means Nagle remains enabled.
|
||||
*
|
||||
* MOSQ_OPT_PROTOCOL_VERSION -
|
||||
* Value must be set to either MQTT_PROTOCOL_V31,
|
||||
* MQTT_PROTOCOL_V311, or MQTT_PROTOCOL_V5. Must be set before the
|
||||
|
||||
@@ -337,6 +337,7 @@ struct mosquitto {
|
||||
#endif
|
||||
uint8_t maximum_qos;
|
||||
uint8_t retain_available;
|
||||
bool tcp_nodelay;
|
||||
|
||||
#ifdef WITH_BROKER
|
||||
UT_hash_handle hh_id;
|
||||
|
||||
@@ -25,6 +25,7 @@ Contributors:
|
||||
#ifndef WIN32
|
||||
#define _GNU_SOURCE
|
||||
#include <netdb.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#else
|
||||
@@ -887,6 +888,13 @@ int net__socket_connect(struct mosquitto *mosq, const char *host, uint16_t port,
|
||||
|
||||
mosq->sock = sock;
|
||||
|
||||
if(mosq->tcp_nodelay){
|
||||
int flag = 1;
|
||||
if(setsockopt(mosq->sock, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(int)) != 0){
|
||||
log__printf(mosq, MOSQ_LOG_WARNING, "Warning: Unable to set TCP_NODELAY.");
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(WITH_SOCKS) && !defined(WITH_BROKER)
|
||||
if(!mosq->socks5_host)
|
||||
#endif
|
||||
|
||||
@@ -447,6 +447,10 @@ int mosquitto_int_option(struct mosquitto *mosq, enum mosq_opt_t option, int val
|
||||
#endif
|
||||
break;
|
||||
|
||||
case MOSQ_OPT_TCP_NODELAY:
|
||||
mosq->tcp_nodelay = (bool)value;
|
||||
break;
|
||||
|
||||
default:
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user