disable nagle algorithm
Ago noticed that some Windows clients experience small packets
from the server being aggregated and set after a long delay
(200-300ms).
He found that TCP_NODELAY on the socket solved this, I tested it
and it didn't have any noticable bad effect, so I implemented it
for all sockets, client and server.
Thans Ago for debugging this and notifying the cause.
Reported-by: Ago Allikmaa <maxorator@gmail.com>
Signed-off-by: Andy Green <andy@warmcat.com>
diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c
index eb9cc85..80d17de 100644
--- a/lib/libwebsockets.c
+++ b/lib/libwebsockets.c
@@ -641,6 +641,7 @@
struct lws_tokens eff_buf;
int ext_count = 0;
struct libwebsocket_extension *ext;
+ int opt = 1;
#ifdef LWS_OPENSSL_SUPPORT
char ssl_err_buf[512];
@@ -706,6 +707,10 @@
break;
}
+ /* Disable Nagle */
+ opt = 1;
+ setsockopt(accept_fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt));
+
if (context->fds_count >= MAX_CLIENTS) {
fprintf(stderr, "too busy to accept new client\n");
#ifdef WIN32
@@ -2416,6 +2421,11 @@
/* allow us to restart even if old sockets in TIME_WAIT */
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
+
+ /* Disable Nagle */
+ opt = 1;
+ setsockopt(sockfd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt));
+
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
if (interf == NULL)