diff options
Diffstat (limited to 'src/cowboy_spdy.erl')
-rw-r--r-- | src/cowboy_spdy.erl | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/cowboy_spdy.erl b/src/cowboy_spdy.erl index ca834ef..faea142 100644 --- a/src/cowboy_spdy.erl +++ b/src/cowboy_spdy.erl @@ -106,24 +106,13 @@ init(Parent, Ref, Socket, Transport, Opts) -> middlewares=Middlewares, env=Env, onrequest=OnRequest, onresponse=OnResponse, peer=Peer, zdef=Zdef, zinf=Zinf}). -parse_frame(State=#state{zinf=Zinf}, Data) -> - case cow_spdy:split(Data) of - {true, Frame, Rest} -> - P = cow_spdy:parse(Frame, Zinf), - State2 = handle_frame(State#state{buffer = Rest}, P), - parse_frame(State2, Rest); - false -> - loop(State#state{buffer=Data}) - end. - loop(State=#state{parent=Parent, socket=Socket, transport=Transport, buffer=Buffer, children=Children}) -> {OK, Closed, Error} = Transport:messages(), Transport:setopts(Socket, [{active, once}]), receive {OK, Socket, Data} -> - Data2 = << Buffer/binary, Data/binary >>, - parse_frame(State, Data2); + parse_frame(State, << Buffer/binary, Data/binary >>); {Closed, Socket} -> terminate(State); {Error, Socket, _Reason} -> @@ -239,6 +228,20 @@ system_terminate(Reason, _, _, _) -> system_code_change(Misc, _, _, _) -> {ok, Misc}. +parse_frame(State=#state{zinf=Zinf}, Data) -> + case cow_spdy:split(Data) of + {true, Frame, Rest} -> + P = cow_spdy:parse(Frame, Zinf), + case handle_frame(State#state{buffer = Rest}, P) of + error -> + terminate(State); + State2 -> + parse_frame(State2, Rest) + end; + false -> + loop(State#state{buffer=Data}) + end. + %% FLAG_UNIDIRECTIONAL can only be set by the server. handle_frame(State, {syn_stream, StreamID, _, _, true, _, _, _, _, _, _, _}) -> @@ -304,7 +307,7 @@ handle_frame(State, {data, StreamID, IsFin, Data}) -> %% General error, can't recover. handle_frame(State, {error, badprotocol}) -> goaway(State, protocol_error), - terminate(State); + error; %% Ignore all other frames for now. handle_frame(State, Frame) -> error_logger:error_msg("Ignored frame ~p", [Frame]), |