Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactored data received from websocket

  • Loading branch information...
commit bd1a22a2630fab50839e84c3c7b4265a6c6fa774 1 parent 6a4c9ea
Roberto Ostinelli authored
Showing with 15 additions and 17 deletions.
  1. +15 −17 src/misultin_websocket.erl
32 src/misultin_websocket.erl
View
@@ -170,24 +170,9 @@ ws_loop(WsHandleLoopPid, SessionsRef, #ws{vsn = Vsn, socket = Socket, socket_mod
misultin_socket:setopts(Socket, [{active, once}], SocketMode),
receive
{tcp, Socket, Data} ->
- VsnMod = get_module_name_from_vsn(Vsn),
- case VsnMod:handle_data(Data, State, {Socket, SocketMode, WsHandleLoopPid}) of
- websocket_close ->
- misultin_websocket:websocket_close(Socket, WsHandleLoopPid, SocketMode, WsAutoExit);
- {websocket_close, CloseData} ->
- misultin_socket:send(Socket, CloseData, SocketMode),
- misultin_websocket:websocket_close(Socket, WsHandleLoopPid, SocketMode, WsAutoExit);
- NewState ->
- ws_loop(WsHandleLoopPid, SessionsRef, Ws, NewState)
- end;
+ handle_data_receive(SessionsRef, WsHandleLoopPid, Data, Ws, State);
{ssl, Socket, Data} ->
- VsnMod = get_module_name_from_vsn(Vsn),
- case VsnMod:handle_data(Data, State, {Socket, SocketMode, WsHandleLoopPid}) of
- {command, websocket_close} ->
- misultin_websocket:websocket_close(Socket, WsHandleLoopPid, SocketMode, WsAutoExit);
- NewState ->
- ws_loop(WsHandleLoopPid, SessionsRef, Ws, NewState)
- end;
+ handle_data_receive(SessionsRef, WsHandleLoopPid, Data, Ws, State);
{WsHandleLoopPid, {wsinfo, WsInfo}} ->
WsResponse = case WsInfo of
raw -> Ws;
@@ -268,6 +253,19 @@ ws_loop(WsHandleLoopPid, SessionsRef, #ws{vsn = Vsn, socket = Socket, socket_mod
ws_loop(WsHandleLoopPid, SessionsRef, Ws, State)
end.
+-spec handle_data_receive(SessionsRef::pid(), WsHandleLoopPid::pid(), Data::binary(), Ws::#ws{}, State::term()) -> ok.
+handle_data_receive(SessionsRef, WsHandleLoopPid, Data, #ws{vsn = Vsn, socket = Socket, socket_mode = SocketMode, ws_autoexit = WsAutoExit} = Ws, State) ->
+ VsnMod = get_module_name_from_vsn(Vsn),
+ case VsnMod:handle_data(Data, State, {Socket, SocketMode, WsHandleLoopPid}) of
+ websocket_close ->
+ misultin_websocket:websocket_close(Socket, WsHandleLoopPid, SocketMode, WsAutoExit);
+ {websocket_close, CloseData} ->
+ misultin_socket:send(Socket, CloseData, SocketMode),
+ misultin_websocket:websocket_close(Socket, WsHandleLoopPid, SocketMode, WsAutoExit);
+ NewState ->
+ ws_loop(WsHandleLoopPid, SessionsRef, Ws, NewState)
+ end.
+
% convert websocket version to module name
-spec get_module_name_from_vsn(Vsn::websocket_version()) -> atom().
get_module_name_from_vsn(Vsn) ->
Please sign in to comment.
Something went wrong with that request. Please try again.