Index: motion.h =================================================================== --- motion.h (revision 305) +++ motion.h (working copy) @@ -347,6 +347,8 @@ time_t eventtime; time_t connectionlosttime; /* timestamp from connection lost */ + int first_header_error_minute; /* minute when first_header error occurred, so we only log one error per minute */ + int lastrate; unsigned short int moved; unsigned short int pause; Index: netcam.c =================================================================== --- netcam.c (revision 305) +++ 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,7 +1612,21 @@ "Error in header (%d)", retval); } /* need to have a dynamic delay here */ - continue; + /* If this error has already occurred in this minute, do not repeat to avoid log-flooding */ + if (netcam->cnt->first_header_error_minute != netcam->cnt->currenttime_tm->tm_min ) + { + /* Record the minute when the error occurred */ + netcam->cnt->first_header_error_minute = netcam->cnt->currenttime_tm->tm_min; + /* And let it happen this time */ + continue; + } + else { + /* Second or subsequent error in this minute - ignore it */ + /* We achieve this by sleeping for 1 minute, since we're in the While loop */ + /* and there's nothing else to do. */ + SLEEP (60,0); + netcam->cnt->first_header_error_minute = -1; /* And turn off the flag until next time */ + }; } } else { /* Streaming */ if (netcam_read_next_header(netcam) < 0) {