mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
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>
This commit is contained in:
parent
98a623fa46
commit
6c9395529e
3 changed files with 15 additions and 0 deletions
|
@ -38,6 +38,7 @@ libwebsocket_client_connect(struct libwebsocket_context *context,
|
|||
struct pollfd pfd;
|
||||
struct libwebsocket *wsi;
|
||||
int n;
|
||||
int opt = 1;
|
||||
int plen = 0;
|
||||
#ifndef LWS_OPENSSL_SUPPORT
|
||||
if (ssl_connection) {
|
||||
|
@ -164,6 +165,9 @@ libwebsocket_client_connect(struct libwebsocket_context *context,
|
|||
server_addr.sin_addr = *((struct in_addr *)server_hostent->h_addr);
|
||||
bzero(&server_addr.sin_zero, 8);
|
||||
|
||||
/* Disable Nagle */
|
||||
setsockopt(wsi->sock, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt));
|
||||
|
||||
if (connect(wsi->sock, (struct sockaddr *)&server_addr,
|
||||
sizeof(struct sockaddr)) == -1) {
|
||||
fprintf(stderr, "Connect failed\n");
|
||||
|
|
|
@ -641,6 +641,7 @@ libwebsocket_service_fd(struct libwebsocket_context *context,
|
|||
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 @@ libwebsocket_service_fd(struct libwebsocket_context *context,
|
|||
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 @@ libwebsocket_create_context(int port, const char *interf,
|
|||
/* 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)
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
#include <sys/prctl.h>
|
||||
#endif
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <poll.h>
|
||||
|
|
Loading…
Add table
Reference in a new issue