Branch: Tag:

2018-10-02

2018-10-02 10:00:08 by Henrik Grubbström (Grubba) <grubba@grubba.org>

WebSocket: Cosmetic change.

61:    ws_onopen(this);   }    - protected void destroy() { + protected void destroy() + {    if (ws_keepalive) {    remove_call_out(ws_keepalive);    }
77:   //! Called to end a socket instead of destructing it. This method will   //! ensure that there are no outstanding handler requests before   //! destructing it. - void end() { + void end() + {    is_ended = 1;       object key = ws_handler_mutex->lock();
92:   //! Handler that processes the msg queue. This method should only be   //! executed by one handler at the time (per request object ofc) or   //! messages may arrive out-of-order to the application. - protected void ws_handle_queue() { + protected void ws_handle_queue() + {    if (!ws_msg_queue->size()) return;       string|Protocols.WebSocket.Frame msg = ws_msg_queue->read();
150:      //! Reschedule this request object for handling websocket messages in   //! queue. - protected void ws_schedule_handling() { + protected void ws_schedule_handling() + {    if (this && !is_ended && !ws_in_handler_queue) {    object key = ws_handler_mutex->lock();    if (!ws_in_handler_queue) {
163:      //! Runs the keep-alive ping over the websocket and reschedules   //! another one. - protected void ws_do_keepalive() { + protected void ws_do_keepalive() + {    // Only send the ping iff we have a ws_ping_interval set and a    // valid, open connection.    if (ws_ping_interval &&
175:   }      //! Reschedule the keep-alive ping for a new time. - protected void ws_reschedule_keepalive() { + protected void ws_reschedule_keepalive() + {    if (ws_keepalive) {    remove_call_out(ws_keepalive);    }
187:   }      //! Callback called when we receive a websocket message. - protected void ws_onmessage(Protocols.WebSocket.Frame frame, mixed id) { + protected void ws_onmessage(Protocols.WebSocket.Frame frame, mixed id) + {    ws_reschedule_keepalive();    ws_msg_queue->write(frame);    ws_schedule_handling();
197:   }      //! Callback called when a CLOSE frame is received. - protected void ws_onclose(Protocols.WebSocket.CLOSE_STATUS reason, mixed id) { + protected void ws_onclose(Protocols.WebSocket.CLOSE_STATUS reason, mixed id) + {    WS_DEBUG("Connection closed.\n");    ws_close_reason = reason;    ws_msg_queue->write(WS_CLOSE_MSG);
216:   //! after the WebSocket connection object has been set up. This means   //! that this method will be called in the same handler thread as the   //! one that returned the upgrade_connection mapping. - protected void ws_onopen(this_program id) { + protected void ws_onopen(this_program id) + {    WS_DEBUG("WebSocket connection open and ready.\n");    ws_msg_queue->write(WS_OPEN_MSG);    this_program::id->json_logger->log(([
229:   //! the @[websocket_close] callback will be triggered.   //!   //! @returns 1 if this isn't an open websocket connection. - public int websocket_close(void|Protocols.WebSocket.CLOSE_STATUS reason) { + public int websocket_close(void|Protocols.WebSocket.CLOSE_STATUS reason) + {    if (state != Protocols.WebSocket.Connection.OPEN) {    return 1;    }