From ca7261ea8d4ff577e97ab374c2742b07428b5e40 Mon Sep 17 00:00:00 2001 From: Nicolas Niclausse Date: Fri, 9 Nov 2012 21:43:43 +0100 Subject: [PATCH] fix tab/spaces --- src/lib/websocket.erl | 14 +++++------ src/tsung/ts_server_websocket.erl | 40 +++++++++++++++---------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/lib/websocket.erl b/src/lib/websocket.erl index d0485d604..12d54e52e 100644 --- a/src/lib/websocket.erl +++ b/src/lib/websocket.erl @@ -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). @@ -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. @@ -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) -> <> = Data, @@ -182,7 +182,7 @@ handle_frame(1, Opcode, Len, Data) -> {close, error} end, - case Rest of + case Rest of <<>> -> {Result, none}; Left -> @@ -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}. diff --git a/src/tsung/ts_server_websocket.erl b/src/tsung/ts_server_websocket.erl index 15ea2c2ad..4bfa37156 100644 --- a/src/tsung/ts_server_websocket.erl +++ b/src/tsung/ts_server_websocket.erl @@ -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, @@ -119,9 +119,9 @@ loop(#state{parent = Parent, socket = Socket, state = connected, buffer = Buffer {tcp, Socket, Data}-> DecodeResult = websocket:decode(<>), case DecodeResult of - {incomplete, Left} -> - ?DebugF("receive incomplete from server: ~p~n", [Left]), - loop(State#state{buffer = <>}); + {incomplete, Left} -> + ?DebugF("receive incomplete from server: ~p~n", [Left]), + loop(State#state{buffer = <>}); {close, Reason} -> ?DebugF("receive close from server: ~p~n", [Reason]), Parent ! {gen_ts_transport, self(), closed}; @@ -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.