diff --git a/examples/userver/userver.cfg.default b/examples/userver/userver.cfg.default index 94295329..8ffbe775 100644 --- a/examples/userver/userver.cfg.default +++ b/examples/userver/userver.cfg.default @@ -189,6 +189,7 @@ userver { # # CGI_TIMEOUT timeout for cgi execution # VIRTUAL_HOST flag to activate practice of maintaining more than one server on one machine, as differentiated by their apparent hostname +# WEBSOCKET_TIMEOUT timeout for websocket request # DIGEST_AUTHENTICATION flag authentication method (yes = digest, no = basic) # # URI_PROTECTED_MASK mask (DOS regexp) of URI protected from prying eyes (that needs authentication) diff --git a/include/ulib/utility/websocket.h b/include/ulib/utility/websocket.h index 3385846b..fea649ca 100644 --- a/include/ulib/utility/websocket.h +++ b/include/ulib/utility/websocket.h @@ -50,6 +50,7 @@ class UHTTP; class USocket; class UCommand; +class UHttpPlugIn; class UDataStorage; class UProxyPlugIn; class UWebSocketClient; @@ -183,8 +184,8 @@ private: static uint32_t max_message_size; static URDBObjectHandler* db; - static int status_code; static UString* rbuffer; + static int status_code, timeoutMS; // the time-out value in milliseconds for client request static const char* upgrade_settings; static WebSocketFrameData control_frame; static WebSocketFrameData message_frame; @@ -199,6 +200,7 @@ private: U_DISALLOW_COPY_AND_ASSIGN(UWebSocket) friend class UHTTP; + friend class UHttpPlugIn; friend class UProxyPlugIn; friend class UWebSocketClient; friend class UWebSocketPlugIn; diff --git a/src/ulib/net/server/plugin/mod_http.cpp b/src/ulib/net/server/plugin/mod_http.cpp index befa17c8..1867647f 100644 --- a/src/ulib/net/server/plugin/mod_http.cpp +++ b/src/ulib/net/server/plugin/mod_http.cpp @@ -11,11 +11,10 @@ // // ============================================================================ -#include #include #include #include -#include +#include #include #include @@ -82,6 +81,7 @@ int UHttpPlugIn::handlerConfig(UFileConfig& cfg) // // CGI_TIMEOUT timeout for cgi execution // VIRTUAL_HOST flag to activate practice of maintaining more than one server on one machine, as differentiated by their apparent hostname + // WEBSOCKET_TIMEOUT timeout for websocket request // DIGEST_AUTHENTICATION flag authentication method (yes = digest, no = basic) // // ENABLE_CACHING_BY_PROXY_SERVERS enable caching by proxy servers (add "Cache control: public" directive) @@ -159,6 +159,10 @@ int UHttpPlugIn::handlerConfig(UFileConfig& cfg) } } + UWebSocket::timeoutMS = cfg.readLong(U_CONSTANT_TO_PARAM("WEBSOCKET_TIMEOUT"), -1); // -1 => no timeout, i.e. an infinite wait + + if (UWebSocket::timeoutMS > 0) UWebSocket::timeoutMS *= 1000; + # ifdef USE_LIBPCRE x = cfg.at(U_CONSTANT_TO_PARAM("REWRITE_RULE_NF")); diff --git a/src/ulib/utility/websocket.cpp b/src/ulib/utility/websocket.cpp index 01822da7..84903598 100644 --- a/src/ulib/utility/websocket.cpp +++ b/src/ulib/utility/websocket.cpp @@ -41,9 +41,10 @@ #define U_WS_GUID "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" #define U_WS_GUID_LEN 36 -int UWebSocket::status_code; int UWebSocket::fd_stderr; +int UWebSocket::status_code; int UWebSocket::message_type; +int UWebSocket::timeoutMS; vPF UWebSocket::on_message; vPFu UWebSocket::on_message_param; UString* UWebSocket::rbuffer; @@ -171,7 +172,7 @@ int UWebSocket::handleDataFraming(USocket* socket) loop: if (rbuffer->empty() && - USocketExt::read(socket, *rbuffer, U_SINGLE_READ, UServer_Base::timeoutMS) == false) + USocketExt::read(socket, *rbuffer, U_SINGLE_READ, UWebSocket::timeoutMS) == false) { status_code = U_WS_STATUS_CODE_INTERNAL_ERROR;