Add MOSQ_OPT_DISABLE_SOCKETPAIR.

pull/2053/head
Roger A. Light 5 years ago
parent fb9ed94b9e
commit c9aa3ca847

@ -1,3 +1,13 @@
2.1.0 - 2021-xx-xx
==================
Client library:
- Add MOSQ_OPT_DISABLE_SOCKETPAIR to allow the disabling of the socketpair
feature that allows the network thread to be woken from select() by another
thread when e.g. mosquitto_publish() is called. This reduces the number of
sockets used by each client by two.
2.0.6 - 2021-01-xx
==================

@ -138,6 +138,7 @@ enum mosq_opt_t {
MOSQ_OPT_TCP_NODELAY = 11,
MOSQ_OPT_BIND_ADDRESS = 12,
MOSQ_OPT_TLS_USE_OS_CERTS = 13,
MOSQ_OPT_DISABLE_SOCKETPAIR = 14,
};
@ -1540,6 +1541,14 @@ libmosq_EXPORT int mosquitto_opts_set(struct mosquitto *mosq, enum mosq_opt_t op
* MOSQ_OPT_TLS_USE_OS_CERTS - Set to 1 to instruct the client to load and
* trust OS provided CA certificates for use with TLS connections.
* Set to 0 (the default) to only use manually specified CA certs.
*
* MOSQ_OPT_DISABLE_SOCKETPAIR - By default, each client connected will create
* an internal pair of connected sockets to allow the network thread
* to be notified and woken up if another thread calls
* <mosquitto_publish> or other similar command. If you are
* operating with an external loop, this is not necessary and
* consumes an extra two sockets per client. Set this option to 1 to
* disable the use of the socket pair.
*/
libmosq_EXPORT int mosquitto_int_option(struct mosquitto *mosq, enum mosq_opt_t option, int value);

@ -213,11 +213,13 @@ int mosquitto_reinitialise(struct mosquitto *mosq, const char *id, bool clean_st
pthread_mutex_init(&mosq->mid_mutex, NULL);
mosq->thread_id = pthread_self();
#endif
/* This must be after pthread_mutex_init(), otherwise the log mutex may be
* used before being initialised. */
if(net__socketpair(&mosq->sockpairR, &mosq->sockpairW)){
log__printf(mosq, MOSQ_LOG_WARNING,
"Warning: Unable to open socket pair, outgoing publish commands may be delayed.");
if(mosq->disable_socketpair == false){
/* This must be after pthread_mutex_init(), otherwise the log mutex may be
* used before being initialised. */
if(net__socketpair(&mosq->sockpairR, &mosq->sockpairW)){
log__printf(mosq, MOSQ_LOG_WARNING,
"Warning: Unable to open socket pair, outgoing publish commands may be delayed.");
}
}
return MOSQ_ERR_SUCCESS;

@ -332,6 +332,7 @@ struct mosquitto {
unsigned int reconnect_delay;
unsigned int reconnect_delay_max;
bool reconnect_exponential_backoff;
bool disable_socketpair;
char threaded;
struct mosquitto__packet *out_packet_last;
mosquitto_property *connect_properties;

@ -416,6 +416,10 @@ int mosquitto_int_option(struct mosquitto *mosq, enum mosq_opt_t option, int val
if(!mosq) return MOSQ_ERR_INVAL;
switch(option){
case MOSQ_OPT_DISABLE_SOCKETPAIR:
mosq->disable_socketpair = (bool)value;
break;
case MOSQ_OPT_PROTOCOL_VERSION:
if(value == MQTT_PROTOCOL_V31){
mosq->protocol = mosq_p_mqtt31;

Loading…
Cancel
Save