Skip to content

Commit

Permalink
add WEBSOCKET_TIMEOUT
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanocasazza committed Dec 14, 2018
1 parent 42f5cee commit a642027
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions examples/userver/userver.cfg.default
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion include/ulib/utility/websocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
class UHTTP;
class USocket;
class UCommand;
class UHttpPlugIn;
class UDataStorage;
class UProxyPlugIn;
class UWebSocketClient;
Expand Down Expand Up @@ -183,8 +184,8 @@ class U_EXPORT UWebSocket {
static uint32_t max_message_size;
static URDBObjectHandler<UDataStorage*>* 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;
Expand All @@ -199,6 +200,7 @@ class U_EXPORT UWebSocket {
U_DISALLOW_COPY_AND_ASSIGN(UWebSocket)

friend class UHTTP;
friend class UHttpPlugIn;
friend class UProxyPlugIn;
friend class UWebSocketClient;
friend class UWebSocketPlugIn;
Expand Down
8 changes: 6 additions & 2 deletions src/ulib/net/server/plugin/mod_http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
//
// ============================================================================

#include <ulib/db/rdb.h>
#include <ulib/command.h>
#include <ulib/file_config.h>
#include <ulib/utility/uhttp.h>
#include <ulib/net/server/server.h>
#include <ulib/utility/websocket.h>
#include <ulib/utility/string_ext.h>
#include <ulib/net/server/plugin/mod_http.h>

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"));

Expand Down
5 changes: 3 additions & 2 deletions src/ulib/utility/websocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit a642027

Please sign in to comment.