aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-06-06 13:48:41 +0200
committerLoïc Hoguin <[email protected]>2011-06-06 13:48:41 +0200
commit2fa1e5392802a271eb530f782e293d2a2a7895a2 (patch)
treeb2b314eb518c4ff5b75bea8986d9feaefdb9e130 /src
parent919fa638ee24250a9f1def27b82f9f7648324d4a (diff)
downloadcowboy-2fa1e5392802a271eb530f782e293d2a2a7895a2.tar.gz
cowboy-2fa1e5392802a271eb530f782e293d2a2a7895a2.tar.bz2
cowboy-2fa1e5392802a271eb530f782e293d2a2a7895a2.zip
Compile the binary match pattern for websockets only once.
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_http_websocket.erl10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/cowboy_http_websocket.erl b/src/cowboy_http_websocket.erl
index 8acc842..1b0691f 100644
--- a/src/cowboy_http_websocket.erl
+++ b/src/cowboy_http_websocket.erl
@@ -23,12 +23,14 @@
origin = undefined :: undefined | binary(),
challenge = undefined :: undefined | binary(),
timeout = infinity :: timeout(),
- messages = undefined :: undefined | {atom(), atom(), atom()}
+ messages = undefined :: undefined | {atom(), atom(), atom()},
+ eop :: tuple()
}).
-spec upgrade(module(), any(), #http_req{}) -> ok.
upgrade(Handler, Opts, Req) ->
- case catch websocket_upgrade(#state{handler=Handler, opts=Opts}, Req) of
+ EOP = binary:compile_pattern(<< 255 >>),
+ case catch websocket_upgrade(#state{handler=Handler, opts=Opts, eop=EOP}, Req) of
{ok, State, Req2} -> handler_init(State, Req2);
{'EXIT', _Reason} -> upgrade_error(Req)
end.
@@ -135,8 +137,8 @@ websocket_data(State, Req, HandlerState, Data) ->
%% We do not support any frame type other than 0 yet. Just like the specs.
-spec websocket_frame(#state{}, #http_req{}, any(), binary(), byte()) -> ok.
-websocket_frame(State, Req, HandlerState, Data, 0) ->
- case binary:match(Data, << 255 >>) of
+websocket_frame(State=#state{eop=EOP}, Req, HandlerState, Data, 0) ->
+ case binary:match(Data, EOP) of
{Pos, 1} ->
Pos2 = Pos - 1,
<< 0, Frame:Pos2/binary, 255, Rest/bits >> = Data,