added websockets tolerance

This commit is contained in:
Unbit
2013-02-16 13:31:01 +01:00
parent 0dd2a34e22
commit 0e502172c9
4 changed files with 22 additions and 14 deletions
+3
View File
@@ -495,6 +495,9 @@ static struct uwsgi_option uwsgi_base_options[] = {
{"websockets-ping-freq", required_argument, 0, "set the frequency (in seconds) of websockets automatic ping packets", uwsgi_opt_set_int, &uwsgi.websockets_ping_freq, 0},
{"websocket-ping-freq", required_argument, 0, "set the frequency (in seconds) of websockets automatic ping packets", uwsgi_opt_set_int, &uwsgi.websockets_ping_freq, 0},
{"websockets-pong-tolerance", required_argument, 0, "set the tolerance (in seconds) of websockets ping/pong subsystem", uwsgi_opt_set_int, &uwsgi.websockets_pong_tolerance, 0},
{"websocket-pong-tolerance", required_argument, 0, "set the tolerance (in seconds) of websockets ping/pong subsystem", uwsgi_opt_set_int, &uwsgi.websockets_pong_tolerance, 0},
{"websockets-max-size", required_argument, 0, "set the max allowed size of websocket messages (in Kbytes, default 1024)", uwsgi_opt_set_64bit, &uwsgi.websockets_max_size, 0},
{"websocket-max-size", required_argument, 0, "set the max allowed size of websocket messages (in Kbytes, default 1024)", uwsgi_opt_set_64bit, &uwsgi.websockets_max_size, 0},
+17 -13
View File
@@ -47,19 +47,22 @@ static int uwsgi_websockets_pong(struct wsgi_request *wsgi_req) {
static int uwsgi_websockets_check_pingpong(struct wsgi_request *wsgi_req) {
time_t now = uwsgi_now();
if (wsgi_req->websocket_last_ping == 0 ||
(now - wsgi_req->websocket_last_ping > uwsgi.websockets_ping_freq)) {
if (uwsgi_websockets_ping(wsgi_req)) return -1;
}
else if (wsgi_req->websocket_last_ping > 0) {
if (wsgi_req->websocket_last_pong < wsgi_req->websocket_last_ping) {
if (wsgi_req->websocket_last_ping - wsgi_req->websocket_last_pong >
uwsgi.websockets_ping_freq) {
uwsgi_log("[uwsgi-websocket] no PONG received in %d seconds !!!\n", uwsgi.websockets_ping_freq);
return -1;
}
}
}
// first round
if (wsgi_req->websocket_last_ping == 0) {
return uwsgi_websockets_ping(wsgi_req);
}
// pong not received ?
if (wsgi_req->websocket_last_pong < wsgi_req->websocket_last_ping) {
if (wsgi_req->websocket_last_ping - wsgi_req->websocket_last_pong > uwsgi.websockets_pong_tolerance) {
uwsgi_log("[uwsgi-websocket] no PONG received in %d seconds !!!\n", uwsgi.websockets_pong_tolerance);
return -1;
}
return 0;
}
// pong received, send anther ping
if (now - wsgi_req->websocket_last_ping >= uwsgi.websockets_ping_freq) {
return uwsgi_websockets_ping(wsgi_req);
}
return 0;
}
@@ -351,5 +354,6 @@ void uwsgi_websockets_init() {
uwsgi.websockets_ping = uwsgi_buffer_new(2);
uwsgi_buffer_append(uwsgi.websockets_ping, "\x89\0", 2);
uwsgi.websockets_ping_freq = 30;
uwsgi.websockets_pong_tolerance = 3;
uwsgi.websockets_max_size = 1024;
}
+1 -1
View File
@@ -603,7 +603,7 @@ void uwsgi_corerouter_loop(int id, void *data) {
if (!ucr->socket_timeout)
ucr->socket_timeout = 30;
ucr->socket_timeout = 60;
if (!ucr->static_node_gracetime)
ucr->static_node_gracetime = 30;
+1
View File
@@ -2187,6 +2187,7 @@ struct uwsgi_server {
struct uwsgi_buffer *websockets_ping;
struct uwsgi_buffer *websockets_pong;
int websockets_ping_freq;
int websockets_pong_tolerance;
uint64_t websockets_max_size;
int (*wait_write_hook) (int, int);