Set TCP_NODELAY by default, CMake option to not use it #530

This commit is contained in:
Ian Craggs 2026-02-12 15:17:43 +00:00
parent 913ee39d24
commit fa7c02e9f5
No known key found for this signature in database
GPG Key ID: A7AE1A8F2CCAB186
2 changed files with 14 additions and 0 deletions

View File

@ -64,6 +64,7 @@ option(PAHO_ENABLE_TESTING "Build tests and run" TRUE)
option(PAHO_ENABLE_CPACK "Enable CPack" TRUE) option(PAHO_ENABLE_CPACK "Enable CPack" TRUE)
option(PAHO_HIGH_PERFORMANCE "Disable tracing and heap tracking" FALSE) option(PAHO_HIGH_PERFORMANCE "Disable tracing and heap tracking" FALSE)
option(PAHO_USE_SELECT "Revert to select system call instead of poll" FALSE) option(PAHO_USE_SELECT "Revert to select system call instead of poll" FALSE)
option(PAHO_NO_TCP_NODELAY "Don't disable Nagle's algorithm on TCP sockets" FALSE)
if(NOT WIN32) if(NOT WIN32)
option(PAHO_WITH_UNIX_SOCKETS "Flag that defines whether to enable Unix-domain sockets" FALSE) option(PAHO_WITH_UNIX_SOCKETS "Flag that defines whether to enable Unix-domain sockets" FALSE)
@ -85,6 +86,10 @@ if(PAHO_WITH_LIBUUID)
add_definitions(-DUSE_LIBUUID=1) add_definitions(-DUSE_LIBUUID=1)
endif() endif()
if(PAHO_NO_TCP_NODELAY)
add_definitions(-DNO_TCP_NODELAY=1)
endif()
if(NOT PAHO_BUILD_SHARED AND NOT PAHO_BUILD_STATIC) if(NOT PAHO_BUILD_SHARED AND NOT PAHO_BUILD_STATIC)
message(FATAL_ERROR "You must set either PAHO_BUILD_SHARED, PAHO_BUILD_STATIC, or both") message(FATAL_ERROR "You must set either PAHO_BUILD_SHARED, PAHO_BUILD_STATIC, or both")
endif() endif()

View File

@ -1462,6 +1462,15 @@ int Socket_new(const char* addr, size_t addr_len, int port, SOCKET* sock)
if (setsockopt(*sock, SOL_SOCKET, SO_NOSIGPIPE, (void*)&opt, sizeof(opt)) != 0) if (setsockopt(*sock, SOL_SOCKET, SO_NOSIGPIPE, (void*)&opt, sizeof(opt)) != 0)
Log(LOG_ERROR, -1, "Could not set SO_NOSIGPIPE for socket %d", *sock); Log(LOG_ERROR, -1, "Could not set SO_NOSIGPIPE for socket %d", *sock);
#endif #endif
#if !defined(NO_TCP_NODELAY)
{
int opt = 1;
socklen_t opt_size = sizeof(opt);
if (setsockopt(*sock, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt)) != 0)
Log(LOG_ERROR, -1, "Could not set TCP_NODELAY for socket %d", *sock);
}
#endif
/*#define SMALL_TCP_BUFFER_TESTING /*#define SMALL_TCP_BUFFER_TESTING
This section sets the TCP send buffer to a small amount to provoke TCPSOCKET_INTERRUPTED This section sets the TCP send buffer to a small amount to provoke TCPSOCKET_INTERRUPTED
return codes from send, for testing only! return codes from send, for testing only!