Index: netcam.c =================================================================== --- netcam.c (revision 296) +++ netcam.c (working copy) @@ -41,6 +41,7 @@ #include #include +#include #include /* For parsing of the URL */ #include #include @@ -759,6 +760,8 @@ fd_set fd_w; struct timeval selecttime; + int window_size=65536; /* Linux doubles the value, and 128Kb is sufficient per netcam */ + /* Assure any previous connection has been closed - IF we are not in keepalive */ if (!netcam->connect_keepalive) { if (debug_level > CAMERA_INFO ) @@ -772,6 +775,27 @@ } if (debug_level > CAMERA_INFO ) motion_log(LOG_DEBUG, 0, "netcam_connect with no keepalive, new socket created fd %d", netcam->sock); + /* Set receive window to new value */ + optval = window_size; + optlen = sizeof(optval); + if(setsockopt(netcam->sock, SOL_SOCKET, SO_RCVBUF, &optval, optlen) < 0) { + motion_log(LOG_ERR, 1, "netcam_connect : Non keepalive, setsockopt() for receive buffer"); + return -1; + } + /* Set send window to new value */ + optval = window_size; + optlen = sizeof(optval); + if(setsockopt(netcam->sock, SOL_SOCKET, SO_SNDBUF, &optval, optlen) < 0) { + motion_log(LOG_ERR, 1, "netcam_connect : Non keepalive, setsockopt() for send buffer"); + return -1; + } + /* Disable Nagles's algorithm to speed up short messages (Eg. http requests) */ + optval = 1; + optlen = sizeof(optval); + if(setsockopt(netcam->sock, IPPROTO_TCP, TCP_NODELAY, (char *)&optval, optlen) < 0) { + motion_log(LOG_ERR, 1, "netcam_connect : Non keepalive, setsockopt() to disable Nagle's algorithm"); + return -1; + } } else { /* We are in keepalive mode, check for invalid socket */ if (netcam->sock == -1) { @@ -805,6 +829,28 @@ } if (debug_level > CAMERA_INFO ) motion_log(LOG_DEBUG, 0, "netcam_connect: SO_KEEPALIVE set on socket."); + + /* Set receive window to new value */ + optval = window_size; + optlen = sizeof(optval); + if(setsockopt(netcam->sock, SOL_SOCKET, SO_RCVBUF, &optval, optlen) < 0) { + motion_log(LOG_ERR, 1, "netcam_connect : Keepalive, setsockopt() for receive buffer"); + return -1; + } + /* Set send window to new value */ + optval = window_size; + optlen = sizeof(optval); + if(setsockopt(netcam->sock, SOL_SOCKET, SO_SNDBUF, &optval, optlen) < 0) { + motion_log(LOG_ERR, 1, "netcam_connect : Keepalive, setsockopt() for send buffer"); + return -1; + } + /* Disable Nagles's algorithm to speed up short messages (Eg. http requests) */ + optval = 1; + optlen = sizeof(optval); + if(setsockopt(netcam->sock, IPPROTO_TCP, TCP_NODELAY, (char *)&optval, optlen) < 0) { + motion_log(LOG_ERR, 1, "netcam_connect : Keepalive, setsockopt() to disable Nagle's algorithm"); + return -1; + } } else { if (debug_level > CAMERA_INFO ) @@ -862,6 +908,7 @@ motion_log(LOG_ERR, 1, "connect() failed (%d)", back_err); motion_log(LOG_DEBUG, 0, "netcam_connect disconnecting netcam (4)" ); netcam_disconnect(netcam); + SLEEP(20,0); /* Delay to let things happen and also to identify in tcpdump */ return -1; } @@ -1565,6 +1612,7 @@ "Error in header (%d)", retval); } /* need to have a dynamic delay here */ + SLEEP(8,0); /* Identifiable delay for now */ continue; } } else { /* Streaming */