Lines Matching refs:ws

50 static PyObject *nxt_py_asgi_websocket_accept(nxt_py_asgi_websocket_t *ws,
52 static PyObject *nxt_py_asgi_websocket_close(nxt_py_asgi_websocket_t *ws,
54 static PyObject *nxt_py_asgi_websocket_send_frame(nxt_py_asgi_websocket_t *ws,
56 static void nxt_py_asgi_websocket_receive_done(nxt_py_asgi_websocket_t *ws,
58 static void nxt_py_asgi_websocket_receive_fail(nxt_py_asgi_websocket_t *ws,
61 static PyObject *nxt_py_asgi_websocket_pop_msg(nxt_py_asgi_websocket_t *ws,
64 nxt_py_asgi_websocket_t *ws);
66 nxt_py_asgi_websocket_t *ws);
68 nxt_py_asgi_websocket_t *ws);
117 nxt_py_asgi_websocket_t *ws; in nxt_py_asgi_websocket_create() local
119 ws = PyObject_New(nxt_py_asgi_websocket_t, &nxt_py_asgi_websocket_type); in nxt_py_asgi_websocket_create()
121 if (nxt_fast_path(ws != NULL)) { in nxt_py_asgi_websocket_create()
122 ws->req = req; in nxt_py_asgi_websocket_create()
123 ws->receive_future = NULL; in nxt_py_asgi_websocket_create()
124 ws->receive_exc_str = NULL; in nxt_py_asgi_websocket_create()
125 ws->state = NXT_WS_INIT; in nxt_py_asgi_websocket_create()
126 nxt_queue_init(&ws->pending_frames); in nxt_py_asgi_websocket_create()
127 ws->pending_payload_len = 0; in nxt_py_asgi_websocket_create()
128 ws->pending_frame_len = 0; in nxt_py_asgi_websocket_create()
129 ws->pending_fins = 0; in nxt_py_asgi_websocket_create()
132 return (PyObject *) ws; in nxt_py_asgi_websocket_create()
141 nxt_py_asgi_websocket_t *ws; in nxt_py_asgi_websocket_receive() local
143 ws = (nxt_py_asgi_websocket_t *) self; in nxt_py_asgi_websocket_receive()
145 nxt_unit_req_debug(ws->req, "asgi_websocket_receive"); in nxt_py_asgi_websocket_receive()
148 if (nxt_slow_path(ws->receive_exc_str != NULL)) { in nxt_py_asgi_websocket_receive()
149 PyErr_SetObject(PyExc_RuntimeError, ws->receive_exc_str); in nxt_py_asgi_websocket_receive()
151 ws->receive_exc_str = NULL; in nxt_py_asgi_websocket_receive()
156 if (nxt_slow_path(ws->state == NXT_WS_CLOSED)) { in nxt_py_asgi_websocket_receive()
157 nxt_unit_req_error(ws->req, in nxt_py_asgi_websocket_receive()
164 ctx_data = ws->req->ctx->data; in nxt_py_asgi_websocket_receive()
168 nxt_unit_req_alert(ws->req, "Python failed to create Future object"); in nxt_py_asgi_websocket_receive()
175 if (nxt_slow_path(ws->state == NXT_WS_INIT)) { in nxt_py_asgi_websocket_receive()
176 ws->state = NXT_WS_CONNECT; in nxt_py_asgi_websocket_receive()
178 msg = nxt_py_asgi_new_msg(ws->req, nxt_py_websocket_connect_str); in nxt_py_asgi_websocket_receive()
180 return nxt_py_asgi_set_result_soon(ws->req, ctx_data, future, msg); in nxt_py_asgi_websocket_receive()
183 if (ws->pending_fins > 0) { in nxt_py_asgi_websocket_receive()
184 msg = nxt_py_asgi_websocket_pop_msg(ws, NULL); in nxt_py_asgi_websocket_receive()
186 return nxt_py_asgi_set_result_soon(ws->req, ctx_data, future, msg); in nxt_py_asgi_websocket_receive()
189 if (nxt_slow_path(ws->state == NXT_WS_DISCONNECTED)) { in nxt_py_asgi_websocket_receive()
190 msg = nxt_py_asgi_websocket_disconnect_msg(ws); in nxt_py_asgi_websocket_receive()
192 return nxt_py_asgi_set_result_soon(ws->req, ctx_data, future, msg); in nxt_py_asgi_websocket_receive()
195 ws->receive_future = future; in nxt_py_asgi_websocket_receive()
196 Py_INCREF(ws->receive_future); in nxt_py_asgi_websocket_receive()
208 nxt_py_asgi_websocket_t *ws; in nxt_py_asgi_websocket_send() local
214 ws = (nxt_py_asgi_websocket_t *) self; in nxt_py_asgi_websocket_send()
218 nxt_unit_req_error(ws->req, "asgi_websocket_send: " in nxt_py_asgi_websocket_send()
226 nxt_unit_req_debug(ws->req, "asgi_websocket_send type is '%.*s'", in nxt_py_asgi_websocket_send()
232 return nxt_py_asgi_websocket_accept(ws, dict); in nxt_py_asgi_websocket_send()
238 return nxt_py_asgi_websocket_close(ws, dict); in nxt_py_asgi_websocket_send()
244 return nxt_py_asgi_websocket_send_frame(ws, dict); in nxt_py_asgi_websocket_send()
247 nxt_unit_req_error(ws->req, "asgi_websocket_send: " in nxt_py_asgi_websocket_send()
254 nxt_py_asgi_websocket_accept(nxt_py_asgi_websocket_t *ws, PyObject *dict) in nxt_py_asgi_websocket_accept() argument
265 switch(ws->state) { in nxt_py_asgi_websocket_accept()
282 if (nxt_slow_path(nxt_unit_response_is_websocket(ws->req))) { in nxt_py_asgi_websocket_accept()
286 if (nxt_slow_path(nxt_unit_response_is_sent(ws->req))) { in nxt_py_asgi_websocket_accept()
315 rc = nxt_unit_response_init(ws->req, 101, in nxt_py_asgi_websocket_accept()
323 add_field_ctx.req = ws->req; in nxt_py_asgi_websocket_accept()
335 rc = nxt_unit_response_add_field(ws->req, in nxt_py_asgi_websocket_accept()
345 rc = nxt_unit_response_send(ws->req); in nxt_py_asgi_websocket_accept()
350 ws->state = NXT_WS_ACCEPTED; in nxt_py_asgi_websocket_accept()
352 Py_INCREF(ws); in nxt_py_asgi_websocket_accept()
354 return (PyObject *) ws; in nxt_py_asgi_websocket_accept()
359 nxt_py_asgi_websocket_close(nxt_py_asgi_websocket_t *ws, PyObject *dict) in nxt_py_asgi_websocket_close() argument
365 if (nxt_slow_path(ws->state == NXT_WS_INIT)) { in nxt_py_asgi_websocket_close()
370 if (nxt_slow_path(ws->state == NXT_WS_DISCONNECTED)) { in nxt_py_asgi_websocket_close()
374 if (nxt_slow_path(ws->state == NXT_WS_CLOSED)) { in nxt_py_asgi_websocket_close()
378 if (nxt_unit_response_is_websocket(ws->req)) { in nxt_py_asgi_websocket_close()
387 rc = nxt_unit_websocket_send(ws->req, NXT_WEBSOCKET_OP_CLOSE, in nxt_py_asgi_websocket_close()
395 rc = nxt_unit_response_init(ws->req, 403, 0, 0); in nxt_py_asgi_websocket_close()
401 rc = nxt_unit_response_send(ws->req); in nxt_py_asgi_websocket_close()
408 ws->state = NXT_WS_CLOSED; in nxt_py_asgi_websocket_close()
410 Py_INCREF(ws); in nxt_py_asgi_websocket_close()
412 return (PyObject *) ws; in nxt_py_asgi_websocket_close()
417 nxt_py_asgi_websocket_send_frame(nxt_py_asgi_websocket_t *ws, PyObject *dict) in nxt_py_asgi_websocket_send_frame() argument
425 if (nxt_slow_path(ws->state == NXT_WS_INIT)) { in nxt_py_asgi_websocket_send_frame()
430 if (nxt_slow_path(ws->state == NXT_WS_CONNECT)) { in nxt_py_asgi_websocket_send_frame()
435 if (nxt_slow_path(ws->state == NXT_WS_DISCONNECTED)) { in nxt_py_asgi_websocket_send_frame()
439 if (nxt_slow_path(ws->state == NXT_WS_CLOSED)) { in nxt_py_asgi_websocket_send_frame()
478 rc = nxt_unit_websocket_send(ws->req, opcode, 1, buf, buf_size); in nxt_py_asgi_websocket_send_frame()
483 Py_INCREF(ws); in nxt_py_asgi_websocket_send_frame()
484 return (PyObject *) ws; in nxt_py_asgi_websocket_send_frame()
495 nxt_py_asgi_websocket_t *ws; in nxt_py_asgi_websocket_handler() local
497 ws = frame->req->data; in nxt_py_asgi_websocket_handler()
499 nxt_unit_req_debug(ws->req, "asgi_websocket_handler"); in nxt_py_asgi_websocket_handler()
509 nxt_unit_req_debug(ws->req, in nxt_py_asgi_websocket_handler()
516 if (nxt_slow_path(ws->state != NXT_WS_ACCEPTED)) { in nxt_py_asgi_websocket_handler()
522 rest = nxt_py_asgi_ws_max_frame_size - ws->pending_frame_len; in nxt_py_asgi_websocket_handler()
530 rest = nxt_py_asgi_ws_max_buffer_size - ws->pending_payload_len; in nxt_py_asgi_websocket_handler()
538 if (ws->receive_future == NULL || frame->header->fin == 0) { in nxt_py_asgi_websocket_handler()
544 if (!nxt_queue_is_empty(&ws->pending_frames)) { in nxt_py_asgi_websocket_handler()
548 nxt_unit_req_alert(ws->req, in nxt_py_asgi_websocket_handler()
562 msg = nxt_py_asgi_websocket_pop_msg(ws, frame); in nxt_py_asgi_websocket_handler()
570 nxt_py_asgi_websocket_receive_done(ws, msg); in nxt_py_asgi_websocket_handler()
576 if (ws->receive_future == NULL) { in nxt_py_asgi_websocket_handler()
577 ws->receive_exc_str = nxt_py_bad_state_str; in nxt_py_asgi_websocket_handler()
586 nxt_unit_req_alert(ws->req, "RuntimeError create failed"); in nxt_py_asgi_websocket_handler()
599 (void) nxt_unit_websocket_send(ws->req, NXT_WEBSOCKET_OP_CLOSE, in nxt_py_asgi_websocket_handler()
602 ws->state = NXT_WS_CLOSED; in nxt_py_asgi_websocket_handler()
604 if (ws->receive_future == NULL) { in nxt_py_asgi_websocket_handler()
605 ws->receive_exc_str = nxt_py_message_too_big_str; in nxt_py_asgi_websocket_handler()
614 nxt_unit_req_alert(ws->req, "RuntimeError create failed"); in nxt_py_asgi_websocket_handler()
623 nxt_py_asgi_websocket_receive_fail(ws, exc); in nxt_py_asgi_websocket_handler()
628 nxt_py_asgi_websocket_receive_done(nxt_py_asgi_websocket_t *ws, PyObject *msg) in nxt_py_asgi_websocket_receive_done() argument
632 future = ws->receive_future; in nxt_py_asgi_websocket_receive_done()
633 ws->receive_future = NULL; in nxt_py_asgi_websocket_receive_done()
637 nxt_unit_req_alert(ws->req, "'set_result' call failed"); in nxt_py_asgi_websocket_receive_done()
649 nxt_py_asgi_websocket_receive_fail(nxt_py_asgi_websocket_t *ws, PyObject *exc) in nxt_py_asgi_websocket_receive_fail() argument
653 future = ws->receive_future; in nxt_py_asgi_websocket_receive_fail()
654 ws->receive_future = NULL; in nxt_py_asgi_websocket_receive_fail()
659 nxt_unit_req_alert(ws->req, "'set_exception' call failed"); in nxt_py_asgi_websocket_receive_fail()
674 nxt_py_asgi_websocket_t *ws; in nxt_py_asgi_websocket_suspend_frame() local
682 ws = frame->req->data; in nxt_py_asgi_websocket_suspend_frame()
686 nxt_unit_req_alert(ws->req, "Failed to retain frame for suspension."); in nxt_py_asgi_websocket_suspend_frame()
698 nxt_unit_req_alert(ws->req, in nxt_py_asgi_websocket_suspend_frame()
710 nxt_queue_insert_tail(&ws->pending_frames, &p->link); in nxt_py_asgi_websocket_suspend_frame()
712 ws->pending_payload_len += frame->payload_len; in nxt_py_asgi_websocket_suspend_frame()
713 ws->pending_fins += frame->header->fin; in nxt_py_asgi_websocket_suspend_frame()
716 ws->pending_frame_len = 0; in nxt_py_asgi_websocket_suspend_frame()
720 ws->pending_frame_len += frame->payload_len; in nxt_py_asgi_websocket_suspend_frame()
723 ws->pending_frame_len = frame->payload_len; in nxt_py_asgi_websocket_suspend_frame()
730 nxt_py_asgi_websocket_pop_msg(nxt_py_asgi_websocket_t *ws, in nxt_py_asgi_websocket_pop_msg() argument
741 nxt_unit_req_debug(ws->req, "asgi_websocket_pop_msg"); in nxt_py_asgi_websocket_pop_msg()
745 if (nxt_queue_is_empty(&ws->pending_frames) in nxt_py_asgi_websocket_pop_msg()
753 payload_len = ws->pending_payload_len + frame->payload_len; in nxt_py_asgi_websocket_pop_msg()
757 payload_len = nxt_py_asgi_websocket_pending_len(ws); in nxt_py_asgi_websocket_pop_msg()
760 frame = nxt_py_asgi_websocket_pop_frame(ws); in nxt_py_asgi_websocket_pop_msg()
766 nxt_unit_req_alert(ws->req, in nxt_py_asgi_websocket_pop_msg()
781 nxt_unit_req_alert(ws->req, in nxt_py_asgi_websocket_pop_msg()
800 nxt_unit_req_alert(ws->req, in nxt_py_asgi_websocket_pop_msg()
829 nxt_unit_req_alert(ws->req, in nxt_py_asgi_websocket_pop_msg()
846 nxt_unit_req_alert(ws->req, "Unexpected opcode %d", opcode); in nxt_py_asgi_websocket_pop_msg()
861 while (!nxt_queue_is_empty(&ws->pending_frames)) { in nxt_py_asgi_websocket_pop_msg()
862 frame = nxt_py_asgi_websocket_pop_frame(ws); in nxt_py_asgi_websocket_pop_msg()
886 nxt_unit_free(ws->req->ctx, buf); in nxt_py_asgi_websocket_pop_msg()
889 nxt_unit_req_alert(ws->req, in nxt_py_asgi_websocket_pop_msg()
900 msg = nxt_py_asgi_new_msg(ws->req, type); in nxt_py_asgi_websocket_pop_msg()
907 nxt_unit_req_alert(ws->req, "Python failed to set 'msg.data' item"); in nxt_py_asgi_websocket_pop_msg()
923 nxt_py_asgi_websocket_pending_len(nxt_py_asgi_websocket_t *ws) in nxt_py_asgi_websocket_pending_len() argument
930 nxt_queue_each(p, &ws->pending_frames, nxt_py_asgi_penging_frame_t, link) { in nxt_py_asgi_websocket_pending_len()
934 nxt_unit_req_debug(ws->req, "asgi_websocket_pending_len: %d", in nxt_py_asgi_websocket_pending_len()
940 nxt_unit_req_debug(ws->req, "asgi_websocket_pending_len: %d (all)", in nxt_py_asgi_websocket_pending_len()
947 nxt_py_asgi_websocket_pop_frame(nxt_py_asgi_websocket_t *ws) in nxt_py_asgi_websocket_pop_frame() argument
953 lnk = nxt_queue_first(&ws->pending_frames); in nxt_py_asgi_websocket_pop_frame()
959 ws->pending_payload_len -= frame->payload_len; in nxt_py_asgi_websocket_pop_frame()
960 ws->pending_fins -= frame->header->fin; in nxt_py_asgi_websocket_pop_frame()
977 nxt_py_asgi_websocket_t *ws; in nxt_py_asgi_websocket_close_handler() local
979 ws = req->data; in nxt_py_asgi_websocket_close_handler()
983 if (nxt_slow_path(ws == NULL)) { in nxt_py_asgi_websocket_close_handler()
987 if (ws->receive_future == NULL) { in nxt_py_asgi_websocket_close_handler()
988 ws->state = NXT_WS_DISCONNECTED; in nxt_py_asgi_websocket_close_handler()
993 msg = nxt_py_asgi_websocket_disconnect_msg(ws); in nxt_py_asgi_websocket_close_handler()
998 nxt_py_asgi_websocket_receive_fail(ws, exc); in nxt_py_asgi_websocket_close_handler()
1001 nxt_py_asgi_websocket_receive_done(ws, msg); in nxt_py_asgi_websocket_close_handler()
1007 nxt_py_asgi_websocket_disconnect_msg(nxt_py_asgi_websocket_t *ws) in nxt_py_asgi_websocket_disconnect_msg() argument
1011 msg = nxt_py_asgi_new_msg(ws->req, nxt_py_websocket_disconnect_str); in nxt_py_asgi_websocket_disconnect_msg()
1018 nxt_unit_req_alert(ws->req, "Python failed to create long"); in nxt_py_asgi_websocket_disconnect_msg()
1027 nxt_unit_req_alert(ws->req, "Python failed to set 'msg.code' item"); in nxt_py_asgi_websocket_disconnect_msg()
1048 nxt_py_asgi_websocket_t *ws; in nxt_py_asgi_websocket_done() local
1050 ws = (nxt_py_asgi_websocket_t *) self; in nxt_py_asgi_websocket_done()
1052 nxt_unit_req_debug(ws->req, "asgi_websocket_done: %p", self); in nxt_py_asgi_websocket_done()
1060 nxt_unit_req_error(ws->req, in nxt_py_asgi_websocket_done()
1072 if (ws->state == NXT_WS_ACCEPTED) { in nxt_py_asgi_websocket_done()
1077 rc = nxt_unit_websocket_send(ws->req, NXT_WEBSOCKET_OP_CLOSE, in nxt_py_asgi_websocket_done()
1081 while (!nxt_queue_is_empty(&ws->pending_frames)) { in nxt_py_asgi_websocket_done()
1082 nxt_unit_websocket_done(nxt_py_asgi_websocket_pop_frame(ws)); in nxt_py_asgi_websocket_done()
1085 nxt_unit_request_done(ws->req, rc); in nxt_py_asgi_websocket_done()