Skip to content

Commit

Permalink
fix tab/spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
nniclausse committed Nov 9, 2012
1 parent 0464f9d commit ca7261e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
14 changes: 7 additions & 7 deletions src/lib/websocket.erl
Expand Up @@ -102,13 +102,13 @@ encode(Data, Opcode) ->
Len < 126 ->
list_to_binary([<<1:1, 0:3, Opcode:4, 1:1, Len:7>>, Key,
mask(Key, Data)]);
Len < 65536 ->
Len < 65536 ->
list_to_binary([<<1:1, 0:3, Opcode:4, 1:1, 126:7, Len:16>>, Key,
mask(Key, Data)]);
true ->
true ->
list_to_binary([<<1:1, 0:3, Opcode:4, 1:1, 127:7, Len:64>>, Key,
mask(Key, Data)])
end.
end.

decode(Data) ->
handle_data(Data).
Expand All @@ -128,7 +128,7 @@ encode_key(Key) ->
A = binary:encode_unsigned(Key),
case size(A) of
4 -> A;
_Other ->
_Other ->
Bits = (4 - _Other) * 8,
<<0:Bits, A/binary>>
end.
Expand Down Expand Up @@ -167,7 +167,7 @@ mask(Key, LongKey, Data, Accu) ->
handle_frame(1, ?OP_CONT, _Len,_Data) ->
{close, seg_not_support};
handle_frame(_,_,Len,Data) when Len > size(Data) ->
{incomplete, Data};
{incomplete, Data};
%%Frame w/o segment
handle_frame(1, Opcode, Len, Data) ->
<<Data1:Len/binary, Rest/binary>> = Data,
Expand All @@ -182,7 +182,7 @@ handle_frame(1, Opcode, Len, Data) ->
{close, error}
end,

case Rest of
case Rest of
<<>> ->
{Result, none};
Left ->
Expand Down Expand Up @@ -213,7 +213,7 @@ handle_data(<<_Fin:1, 0:3, _Opcode:4,_:1, 127:7, 1:1, _PayloadLen:63,
{close, error};
handle_data(<<_Fin:1, 0:3, _Opcode:4, 1:1, _PayloadLen:7,
_PayloadData/binary>>) ->
%% Error, Server to client message can't be masked
%% Error, Server to client message can't be masked
{close, masked}.


Expand Down
40 changes: 20 additions & 20 deletions src/tsung/ts_server_websocket.erl
Expand Up @@ -56,25 +56,25 @@ connect(Host, Port, Opts) ->
Path = WSConfig#ws_config.path,
Version = WSConfig#ws_config.version,

case gen_tcp:connect(Host, Port, opts_to_tcp_opts(TcpOpts)) of
{ok, Socket} ->
Pid = spawn_link(
fun() ->
loop(#state{parent = Parent, host = Host, port = Port,
opts = TcpOpts, path = Path, version = Version,
socket = Socket})
end),
gen_tcp:controlling_process(Socket, Pid),
inet:setopts(Socket, [{active, once}]),
{ok, Pid};
Ret ->
Ret
end.
case gen_tcp:connect(Host, Port, opts_to_tcp_opts(TcpOpts)) of
{ok, Socket} ->
Pid = spawn_link(
fun() ->
loop(#state{parent = Parent, host = Host, port = Port,
opts = TcpOpts, path = Path, version = Version,
socket = Socket})
end),
gen_tcp:controlling_process(Socket, Pid),
inet:setopts(Socket, [{active, once}]),
{ok, Pid};
Ret ->
Ret
end.

loop(#state{socket = Socket, host = Host, path = Path, port = Port, opts = Opts,
version = Version, subprotos = SubProtocol,
state = not_connected} = State)->
{Handshake, Accept} = websocket:handshake_request(Host, Path,
{Handshake, Accept} = websocket:handshake_request(Host, Path,
SubProtocol, Version),
gen_tcp:send(Socket, Handshake),
loop(State#state{socket = Socket, accept = Accept,
Expand Down Expand Up @@ -119,9 +119,9 @@ loop(#state{parent = Parent, socket = Socket, state = connected, buffer = Buffer
{tcp, Socket, Data}->
DecodeResult = websocket:decode(<<Buffer/binary, Data/binary>>),
case DecodeResult of
{incomplete, Left} ->
?DebugF("receive incomplete from server: ~p~n", [Left]),
loop(State#state{buffer = <<Buffer/binary, Left/binary>>});
{incomplete, Left} ->
?DebugF("receive incomplete from server: ~p~n", [Left]),
loop(State#state{buffer = <<Buffer/binary, Left/binary>>});
{close, Reason} ->
?DebugF("receive close from server: ~p~n", [Reason]),
Parent ! {gen_ts_transport, self(), closed};
Expand Down Expand Up @@ -170,7 +170,7 @@ set_opts(Socket, Opts) ->
Socket.

normalize_incomming_data(_Socket, X) ->
%% nothing to do here, ts_websocket uses a special process to handle
%%http requests,the incoming data is already delivered to
%% nothing to do here, ts_websocket uses a special process to handle
%%http requests,the incoming data is already delivered to
%%ts_client as {gen_ts_transport, ..} instead of gen_tcp | ssl
X.

0 comments on commit ca7261e

Please sign in to comment.