Permalink
Browse files

refactored websocket hybi 10 and 17 code to have a common module

  • Loading branch information...
1 parent 1b1fdad commit 387fdb3b78ccc610dc553ac7c35499a8ea7845b6 @ostinelli ostinelli committed with Nov 20, 2011
@@ -221,8 +221,8 @@ ws_loop(WsHandleLoopPid, #ws{vsn = Vsn, socket = Socket, socket_mode = SocketMod
% close websocket and custom controlling loop
websocket_close(Socket, WsHandleLoopPid, SocketMode, WsAutoExit);
{send, Data} ->
- ?LOG_DEBUG("sending data to websocket: ~p", [Data]),
VsnMod = get_module_name_from_vsn(Vsn),
+ ?LOG_DEBUG("sending data: ~p to websocket module: ~p", [Data, VsnMod]),
misultin_socket:send(Socket, VsnMod:send_format(Data, State), SocketMode),
ws_loop(WsHandleLoopPid, Ws, State);
shutdown ->
@@ -81,23 +81,23 @@ handshake(#req{socket_mode = SocketMode, ws_force_ssl = WsForceSsl} = _Req, _Hea
].
% ----------------------------------------------------------------------------------------------------------
-% Function: -> websocket_close | {websocket_close, DataToSendBeforeClose::binary() | iolist()} | NewStatus
+% Function: -> websocket_close | {websocket_close, DataToSendBeforeClose::binary() | iolist()} | NewState
% Description: Callback to handle incomed data.
% ----------------------------------------------------------------------------------------------------------
--spec handle_data(Data::binary(), Status::undefined | term(), {Socket::socket(), SocketMode::socketmode(), WsHandleLoopPid::pid()}) -> websocket_close | term().
+-spec handle_data(Data::binary(), State::undefined | term(), {Socket::socket(), SocketMode::socketmode(), WsHandleLoopPid::pid()}) -> websocket_close | term().
handle_data(Data, undefined, {Socket, SocketMode, WsHandleLoopPid}) ->
% init status
handle_data(Data, {buffer, none}, {Socket, SocketMode, WsHandleLoopPid});
-handle_data(Data, {buffer, B} = _Status, {Socket, SocketMode, WsHandleLoopPid}) ->
+handle_data(Data, {buffer, B} = _State, {Socket, SocketMode, WsHandleLoopPid}) ->
% read status
i_handle_data(Data, B, {Socket, SocketMode, WsHandleLoopPid}).
% ----------------------------------------------------------------------------------------------------------
% Function: -> binary() | iolist()
% Description: Callback to format data before it is sent into the socket.
% ----------------------------------------------------------------------------------------------------------
--spec send_format(Data::iolist(), Status::term()) -> iolist().
-send_format(Data, _Status) ->
+-spec send_format(Data::iolist(), State::term()) -> iolist().
+send_format(Data, _State) ->
[0, Data, 255].
% ============================ /\ API ======================================================================
@@ -110,10 +110,10 @@ handshake(#req{socket = Sock, socket_mode = SocketMode, ws_force_ssl = WsForceSs
].
% ----------------------------------------------------------------------------------------------------------
-% Function: -> websocket_close | {websocket_close, DataToSendBeforeClose::binary() | iolist()} | NewStatus
+% Function: -> websocket_close | {websocket_close, DataToSendBeforeClose::binary() | iolist()} | NewState
% Description: Callback to handle incomed data.
% ----------------------------------------------------------------------------------------------------------
--spec handle_data(Data::binary(), Status::undefined | term(), {Socket::socket(), SocketMode::socketmode(), WsHandleLoopPid::pid()}) -> websocket_close | term().
+-spec handle_data(Data::binary(), State::undefined | term(), {Socket::socket(), SocketMode::socketmode(), WsHandleLoopPid::pid()}) -> websocket_close | term().
handle_data(Data, undefined, {Socket, SocketMode, WsHandleLoopPid}) ->
% init status
handle_data(Data, {buffer, none}, {Socket, SocketMode, WsHandleLoopPid});
@@ -125,7 +125,7 @@ handle_data(Data, {buffer, B} = _State, {Socket, SocketMode, WsHandleLoopPid}) -
% Function: -> binary() | iolist()
% Description: Callback to format data before it is sent into the socket.
% ----------------------------------------------------------------------------------------------------------
--spec send_format(Data::iolist(), Status::term()) -> iolist().
+-spec send_format(Data::iolist(), State::term()) -> iolist().
send_format(Data, _State) ->
[0, Data, 255].
Oops, something went wrong. Retry.

0 comments on commit 387fdb3

Please sign in to comment.