mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-03-23 16:33:35 +08:00
committed by
Roger Light
parent
5ce4f07f6a
commit
0a64c1de23
35
src/bridge.c
35
src/bridge.c
@@ -189,29 +189,38 @@ void bridge__start_all(void)
|
||||
|
||||
static int bridge__set_tcp_keepalive(struct mosquitto *context)
|
||||
{
|
||||
unsigned int idle = context->bridge->tcp_keepalive_idle;
|
||||
unsigned int interval = context->bridge->tcp_keepalive_interval;
|
||||
unsigned int counter = context->bridge->tcp_keepalive_counter;
|
||||
unsigned int enabled = 1;
|
||||
bool ret;
|
||||
|
||||
if(idle == 0 || interval == 0 || counter == 0){
|
||||
if(context->bridge->tcp_keepalive_idle == 0
|
||||
|| context->bridge->tcp_keepalive_interval == 0
|
||||
|| context->bridge->tcp_keepalive_counter == 0){
|
||||
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
ret = setsockopt(context->sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&enabled, sizeof(enabled)) ||
|
||||
setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPIDLE, (char *)&idle, sizeof(idle)) ||
|
||||
setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPINTVL, (char *)&interval, sizeof(interval)) ||
|
||||
setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPCNT, (char *)&counter, sizeof(counter));
|
||||
# define SETSOCKOPT_TYPE char *
|
||||
#else
|
||||
ret = setsockopt(context->sock, SOL_SOCKET, SO_KEEPALIVE, (const void *)&enabled, sizeof(enabled)) ||
|
||||
#ifndef __APPLE__
|
||||
setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPIDLE, (const void *)&idle, sizeof(idle)) ||
|
||||
# define SETSOCKOPT_TYPE const void *
|
||||
#endif
|
||||
setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPINTVL, (const void *)&interval, sizeof(interval)) ||
|
||||
setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPCNT, (const void *)&counter, sizeof(counter));
|
||||
|
||||
ret = setsockopt(context->sock, SOL_SOCKET, SO_KEEPALIVE, (SETSOCKOPT_TYPE)&enabled, sizeof(enabled));
|
||||
|
||||
#ifdef TCP_KEEPIDLE
|
||||
ret = ret || setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPIDLE,
|
||||
(SETSOCKOPT_TYPE)&context->bridge->tcp_keepalive_idle, sizeof(context->bridge->tcp_keepalive_idle));
|
||||
#endif
|
||||
#ifdef TCP_KEEPINTVL
|
||||
ret = ret || setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPINTVL,
|
||||
(SETSOCKOPT_TYPE)&context->bridge->tcp_keepalive_interval, sizeof(context->bridge->tcp_keepalive_interval));
|
||||
#endif
|
||||
#ifdef TCP_KEEPCNT
|
||||
ret = ret || setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPCNT,
|
||||
(SETSOCKOPT_TYPE)&context->bridge->tcp_keepalive_counter, sizeof(context->bridge->tcp_keepalive_counter));
|
||||
#endif
|
||||
|
||||
#undef SETSOCKOPT_TYPE
|
||||
|
||||
if(ret){
|
||||
return MOSQ_ERR_UNKNOWN;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
# include <ws2tcpip.h>
|
||||
#else
|
||||
# include <arpa/inet.h>
|
||||
# include <netinet/in.h>
|
||||
#endif
|
||||
#include <stdint.h>
|
||||
#include "mosquitto_broker_internal.h"
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
# include <ws2tcpip.h>
|
||||
#else
|
||||
# include <arpa/inet.h>
|
||||
# include <netinet/in.h>
|
||||
#endif
|
||||
#include <stdint.h>
|
||||
#include "mosquitto_broker_internal.h"
|
||||
|
||||
Reference in New Issue
Block a user