diff --git a/include/HTTPserver.h b/include/HTTPserver.h index 0317c61ef0..13edb6d7ba 100644 --- a/include/HTTPserver.h +++ b/include/HTTPserver.h @@ -47,6 +47,7 @@ class HTTPserver { bool valid_user_pwd(char *user, char *pass); static bool authorized_localhost_user_login(const struct mg_connection *conn); + static bool sender_queue_free_space(const struct mg_connection *conn, u_int32_t space_needed); inline char* get_docs_dir() { return(docs_dir); }; inline char* get_scripts_dir() { return(scripts_dir); }; diff --git a/src/HTTPserver.cpp b/src/HTTPserver.cpp index 154a988996..0042eca612 100644 --- a/src/HTTPserver.cpp +++ b/src/HTTPserver.cpp @@ -110,6 +110,30 @@ static void generate_session_id(char *buf, const char *random, const char *user) /* ****************************************** */ +bool HTTPserver::sender_queue_free_space(const struct mg_connection *conn, u_int32_t space_needed) { + int free_space = 0, send_buf, unsent_buf; + + if(conn) { +#if defined(linux) && defined(SIOCOUTQ) + + socklen_t optlen = sizeof(send_buf); + + if(!getsockopt(conn->client.sock, SOL_SOCKET, SO_SNDBUF, &send_buf, (socklen_t*)&optlen) + && !ioctl(conn->client.sock, SIOCOUTQ, &unsent_buf)) { + if(send_buf > unsent_buf) + free_space = send_buf - unsent_buf; + + ntop->getTrace()->traceEvent(TRACE_NORMAL, "SO_SNDBUF: %d SIOCOUTQ: %d (free space: %d)", send_buf, unsent_buf, free_space); + } +#endif + + } + + return((int)space_needed < 2 * free_space ? true : false); +} + +/* ****************************************** */ + bool HTTPserver::authorized_localhost_user_login(const struct mg_connection *conn) { if(ntop->getPrefs()->is_localhost_users_login_disabled() && (conn->request_info.remote_ip == 0x7F000001 /* 127.0.0.1 */)) diff --git a/src/NetworkInterface.cpp b/src/NetworkInterface.cpp index 269b8028a2..f60a413c84 100644 --- a/src/NetworkInterface.cpp +++ b/src/NetworkInterface.cpp @@ -6614,6 +6614,13 @@ void NetworkInterface::deliverLiveCapture(const struct pcap_pkthdr * const h, num_found++; +#if 0 + if(!HTTPserver::sender_queue_free_space(c->conn, h->len)) { + ntop->getTrace()->traceEvent(TRACE_NORMAL, "Skipping packet, buffer full"); + continue; + } +#endif + if(c->live_capture.capture_until < h->ts.tv_sec || c->live_capture.stopped) http_client_disconnected = true;