Deleted
Added
nxt_h1proto_websocket.c (1417:039b00e32e3d) | nxt_h1proto_websocket.c (1956:f4c32c2d595d) |
---|---|
1 2/* 3 * Copyright (C) NGINX, Inc. 4 */ 5 6#include <nxt_main.h> 7#include <nxt_router.h> 8#include <nxt_http.h> --- 59 unchanged lines hidden (view full) --- 68static const nxt_ws_error_t nxt_ws_err_cont_expected = { 69 NXT_WEBSOCKET_CR_PROTOCOL_ERROR, 70 1, nxt_string("Continuation expected, but %ud opcode received") }; 71 72void 73nxt_h1p_websocket_first_frame_start(nxt_task_t *task, nxt_http_request_t *r, 74 nxt_buf_t *ws_frame) 75{ | 1 2/* 3 * Copyright (C) NGINX, Inc. 4 */ 5 6#include <nxt_main.h> 7#include <nxt_router.h> 8#include <nxt_http.h> --- 59 unchanged lines hidden (view full) --- 68static const nxt_ws_error_t nxt_ws_err_cont_expected = { 69 NXT_WEBSOCKET_CR_PROTOCOL_ERROR, 70 1, nxt_string("Continuation expected, but %ud opcode received") }; 71 72void 73nxt_h1p_websocket_first_frame_start(nxt_task_t *task, nxt_http_request_t *r, 74 nxt_buf_t *ws_frame) 75{ |
76 nxt_conn_t *c; 77 nxt_timer_t *timer; 78 nxt_h1proto_t *h1p; 79 nxt_socket_conf_joint_t *joint; | 76 nxt_conn_t *c; 77 nxt_timer_t *timer; 78 nxt_h1proto_t *h1p; 79 nxt_websocket_conf_t *websocket_conf; |
80 81 nxt_debug(task, "h1p ws first frame start"); 82 83 h1p = r->proto.h1; 84 c = h1p->conn; 85 86 if (!c->tcp_nodelay) { 87 nxt_conn_tcp_nodelay_on(task, c); 88 } 89 | 80 81 nxt_debug(task, "h1p ws first frame start"); 82 83 h1p = r->proto.h1; 84 c = h1p->conn; 85 86 if (!c->tcp_nodelay) { 87 nxt_conn_tcp_nodelay_on(task, c); 88 } 89 |
90 joint = c->listen->socket.data; | 90 websocket_conf = &r->conf->socket_conf->websocket_conf; |
91 | 91 |
92 if (nxt_slow_path(joint != NULL 93 && joint->socket_conf->websocket_conf.keepalive_interval != 0)) 94 { | 92 if (nxt_slow_path(websocket_conf->keepalive_interval != 0)) { |
95 h1p->websocket_timer = nxt_mp_zget(c->mem_pool, 96 sizeof(nxt_h1p_websocket_timer_t)); 97 if (nxt_slow_path(h1p->websocket_timer == NULL)) { 98 hxt_h1p_send_ws_error(task, r, &nxt_ws_err_out_of_memory); 99 return; 100 } 101 102 h1p->websocket_timer->keepalive_interval = | 93 h1p->websocket_timer = nxt_mp_zget(c->mem_pool, 94 sizeof(nxt_h1p_websocket_timer_t)); 95 if (nxt_slow_path(h1p->websocket_timer == NULL)) { 96 hxt_h1p_send_ws_error(task, r, &nxt_ws_err_out_of_memory); 97 return; 98 } 99 100 h1p->websocket_timer->keepalive_interval = |
103 joint->socket_conf->websocket_conf.keepalive_interval; | 101 websocket_conf->keepalive_interval; |
104 h1p->websocket_timer->h1p = h1p; 105 106 timer = &h1p->websocket_timer->timer; 107 timer->task = &c->task; 108 timer->work_queue = &task->thread->engine->fast_work_queue; 109 timer->log = &c->log; 110 timer->bias = NXT_TIMER_DEFAULT_BIAS; 111 timer->handler = nxt_h1p_conn_ws_keepalive; --- 101 unchanged lines hidden (view full) --- 213 .timer_data = offsetof(nxt_socket_conf_t, websocket_conf.read_timeout), 214 .timer_autoreset = 1, 215}; 216 217 218static void 219nxt_h1p_conn_ws_frame_header_read(nxt_task_t *task, void *obj, void *data) 220{ | 102 h1p->websocket_timer->h1p = h1p; 103 104 timer = &h1p->websocket_timer->timer; 105 timer->task = &c->task; 106 timer->work_queue = &task->thread->engine->fast_work_queue; 107 timer->log = &c->log; 108 timer->bias = NXT_TIMER_DEFAULT_BIAS; 109 timer->handler = nxt_h1p_conn_ws_keepalive; --- 101 unchanged lines hidden (view full) --- 211 .timer_data = offsetof(nxt_socket_conf_t, websocket_conf.read_timeout), 212 .timer_autoreset = 1, 213}; 214 215 216static void 217nxt_h1p_conn_ws_frame_header_read(nxt_task_t *task, void *obj, void *data) 218{ |
221 size_t size, hsize, frame_size, max_frame_size; 222 uint64_t payload_len; 223 nxt_conn_t *c; 224 nxt_h1proto_t *h1p; 225 nxt_http_request_t *r; 226 nxt_event_engine_t *engine; 227 nxt_websocket_header_t *wsh; 228 nxt_socket_conf_joint_t *joint; | 219 size_t size, hsize, frame_size, max_frame_size; 220 uint64_t payload_len; 221 nxt_conn_t *c; 222 nxt_h1proto_t *h1p; 223 nxt_http_request_t *r; 224 nxt_event_engine_t *engine; 225 nxt_websocket_header_t *wsh; |
229 230 c = obj; 231 h1p = data; 232 233 nxt_h1p_conn_ws_keepalive_disable(task, h1p); 234 235 size = nxt_buf_mem_used_size(&c->read->mem); 236 --- 23 unchanged lines hidden (view full) --- 260 261 r = h1p->request; 262 if (nxt_slow_path(r == NULL)) { 263 return; 264 } 265 266 r->ws_frame = c->read; 267 | 226 227 c = obj; 228 h1p = data; 229 230 nxt_h1p_conn_ws_keepalive_disable(task, h1p); 231 232 size = nxt_buf_mem_used_size(&c->read->mem); 233 --- 23 unchanged lines hidden (view full) --- 257 258 r = h1p->request; 259 if (nxt_slow_path(r == NULL)) { 260 return; 261 } 262 263 r->ws_frame = c->read; 264 |
268 joint = c->listen->socket.data; 269 270 if (nxt_slow_path(joint == NULL)) { 271 /* 272 * Listening socket had been closed while 273 * connection was in keep-alive state. 274 */ 275 c->read_state = &nxt_h1p_idle_close_state; 276 return; 277 } 278 | |
279 if (nxt_slow_path(wsh->mask == 0)) { 280 hxt_h1p_send_ws_error(task, r, &nxt_ws_err_not_masked); 281 return; 282 } 283 284 if ((wsh->opcode & NXT_WEBSOCKET_OP_CTRL) != 0) { 285 if (nxt_slow_path(wsh->fin == 0)) { 286 hxt_h1p_send_ws_error(task, r, &nxt_ws_err_ctrl_fragmented); --- 38 unchanged lines hidden (view full) --- 325 wsh->opcode); 326 return; 327 } 328 } 329 330 h1p->websocket_cont_expected = !wsh->fin; 331 } 332 | 265 if (nxt_slow_path(wsh->mask == 0)) { 266 hxt_h1p_send_ws_error(task, r, &nxt_ws_err_not_masked); 267 return; 268 } 269 270 if ((wsh->opcode & NXT_WEBSOCKET_OP_CTRL) != 0) { 271 if (nxt_slow_path(wsh->fin == 0)) { 272 hxt_h1p_send_ws_error(task, r, &nxt_ws_err_ctrl_fragmented); --- 38 unchanged lines hidden (view full) --- 311 wsh->opcode); 312 return; 313 } 314 } 315 316 h1p->websocket_cont_expected = !wsh->fin; 317 } 318 |
333 max_frame_size = joint->socket_conf->websocket_conf.max_frame_size; | 319 max_frame_size = r->conf->socket_conf->websocket_conf.max_frame_size; |
334 335 payload_len = nxt_websocket_frame_payload_len(wsh); 336 337 if (nxt_slow_path(hsize > max_frame_size 338 || payload_len > (max_frame_size - hsize))) 339 { 340 hxt_h1p_send_ws_error(task, r, &nxt_ws_err_too_big, payload_len); 341 return; --- 375 unchanged lines hidden --- | 320 321 payload_len = nxt_websocket_frame_payload_len(wsh); 322 323 if (nxt_slow_path(hsize > max_frame_size 324 || payload_len > (max_frame_size - hsize))) 325 { 326 hxt_h1p_send_ws_error(task, r, &nxt_ws_err_too_big, payload_len); 327 return; --- 375 unchanged lines hidden --- |