couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [40/50] mochiweb commit: updated refs/heads/1843-feature-bigcouch to 432c949
Date Thu, 17 Apr 2014 18:17:08 GMT
some more whitespace tweaks, use full bytes in payload_length/1


Project: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/commit/49eaab98
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/tree/49eaab98
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/diff/49eaab98

Branch: refs/heads/1843-feature-bigcouch
Commit: 49eaab98a5bf15b4f6ba0846c9e5057f10df95cb
Parents: 74d6cdc
Author: Bob Ippolito <bob@redivi.com>
Authored: Thu Dec 26 13:06:56 2013 -0800
Committer: Bob Ippolito <bob@redivi.com>
Committed: Thu Dec 26 13:06:56 2013 -0800

----------------------------------------------------------------------
 src/mochiweb_websocket.erl | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/49eaab98/src/mochiweb_websocket.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb_websocket.erl b/src/mochiweb_websocket.erl
index e5aff05..cc3127e 100644
--- a/src/mochiweb_websocket.erl
+++ b/src/mochiweb_websocket.erl
@@ -69,27 +69,23 @@ call_body(Body, Payload, State, ReplyChannel) ->
     Body(Payload, State, ReplyChannel).
 
 send(Socket, Payload, hybi) ->
-    Len = payload_length(iolist_size(Payload)),
-    Data = <<1:1, 0:3, 1:4, 0:1, Len/bits, Payload/binary>>,
-    mochiweb_socket:send(Socket, Data);
+    Prefix = <<1:1, 0:3, 1:4, (payload_length(iolist_size(Payload)))/binary>>,
+    mochiweb_socket:send(Socket, [Prefix, Payload]);
 send(Socket, Payload, hixie) ->
-    Data = <<0, Payload/binary, 255>>,
-    mochiweb_socket:send(Socket, Data).
+    mochiweb_socket:send(Socket, [0, Payload, 255]).
 
 upgrade_connection(Req, Body) ->
     case make_handshake(Req) of
         {Version, Response} ->
             Req:respond(Response),
-
             Socket = Req:get(socket),
-            ReplyChannel = fun(Payload) ->
+            ReplyChannel = fun (Payload) ->
                 ?MODULE:send(Socket, Payload, Version)
             end,
             Reentry = fun (State) ->
                 ?MODULE:loop(Socket, Body, State, Version, ReplyChannel)
             end,
             {Reentry, ReplyChannel};
-
         _ ->
             mochiweb_socket:close(Req:get(socket)),
             exit(normal)
@@ -207,7 +203,6 @@ parse_hybi_frames(Socket, <<_Fin:1,
                            _MaskKey:4/binary,
                            _/binary-unit:8>> = PartFrame,
                   Acc) ->
-
     ok = mochiweb_socket:setopts(Socket, [{packet, 0}, {active, once}]),
     receive
         {tcp_closed, _} ->
@@ -226,9 +221,9 @@ parse_hybi_frames(Socket, <<_Fin:1,
             mochiweb_socket:close(Socket),
             exit(normal)
     after
-      5000 ->
-        mochiweb_socket:close(Socket),
-        exit(normal)
+        5000 ->
+            mochiweb_socket:close(Socket),
+            exit(normal)
     end;
 parse_hybi_frames(S, <<_Fin:1,
                       _Rsv:3,
@@ -262,9 +257,9 @@ hybi_unmask(<<>>, _MaskKey, Acc) ->
 
 payload_length(N) ->
     case N of
-        N when N =< 125 -> << N:7 >>;
-        N when N =< 16#ffff -> << 126:7, N:16 >>;
-        N when N =< 16#7fffffffffffffff -> << 127:7, N:64 >>
+        N when N =< 125 -> << N >>;
+        N when N =< 16#ffff -> << 126, N:16 >>;
+        N when N =< 16#7fffffffffffffff -> << 127, N:64 >>
     end.
 
 


Mime
View raw message