mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 04:10:24 +00:00
Cleanup logs
This commit is contained in:
parent
ee6ef37643
commit
a8cc1d8144
1 changed files with 19 additions and 11 deletions
|
@ -9,7 +9,15 @@
|
|||
-export([webtransport_info/2]).
|
||||
-export([terminate/3]).
|
||||
|
||||
%% -define(DEBUG, 1).
|
||||
-ifdef(DEBUG).
|
||||
-define(LOG(Fmt, Args), ct:pal(Fmt, Args)).
|
||||
-else.
|
||||
-define(LOG(Fmt, Args), _ = Fmt, _ = Args, ok).
|
||||
-endif.
|
||||
|
||||
init(Req0, _) ->
|
||||
?LOG("WT init ~p~n", [Req0]),
|
||||
Req = case cowboy_req:parse_header(<<"wt-available-protocols">>, Req0) of
|
||||
undefined ->
|
||||
Req0;
|
||||
|
@ -21,16 +29,16 @@ init(Req0, _) ->
|
|||
%% @todo WT handle {stream_open,4,bidi}
|
||||
|
||||
webtransport_handle(Event = {stream_open, StreamID, bidi}, Streams) ->
|
||||
ct:pal("WT handle ~p~n", [Event]),
|
||||
?LOG("WT handle ~p~n", [Event]),
|
||||
{[], Streams#{StreamID => bidi}};
|
||||
webtransport_handle(Event = {stream_open, StreamID, unidi}, Streams) ->
|
||||
ct:pal("WT handle ~p~n", [Event]),
|
||||
?LOG("WT handle ~p~n", [Event]),
|
||||
OpenStreamRef = make_ref(),
|
||||
{[{open_stream, OpenStreamRef, unidi, <<>>}], Streams#{
|
||||
StreamID => {unidi_remote, OpenStreamRef},
|
||||
OpenStreamRef => {unidi_local, StreamID}}};
|
||||
webtransport_handle(Event = {opened_stream_id, OpenStreamRef, OpenStreamID}, Streams) ->
|
||||
ct:pal("WT handle ~p~n", [Event]),
|
||||
?LOG("WT handle ~p~n", [Event]),
|
||||
case Streams of
|
||||
#{OpenStreamRef := bidi} ->
|
||||
{[], maps:remove(OpenStreamRef, Streams#{
|
||||
|
@ -44,7 +52,7 @@ webtransport_handle(Event = {opened_stream_id, OpenStreamRef, OpenStreamID}, Str
|
|||
})}
|
||||
end;
|
||||
webtransport_handle(Event = {stream_data, StreamID, _IsFin, <<"TEST:", Test/bits>>}, Streams) ->
|
||||
ct:pal("WT handle ~p~n", [Event]),
|
||||
?LOG("WT handle ~p~n", [Event]),
|
||||
case Test of
|
||||
<<"open_bidi">> ->
|
||||
OpenStreamRef = make_ref(),
|
||||
|
@ -63,7 +71,7 @@ webtransport_handle(Event = {stream_data, StreamID, _IsFin, <<"TEST:", Test/bits
|
|||
Streams#{event_pid => binary_to_term(EventPidBin)}}
|
||||
end;
|
||||
webtransport_handle(Event = {stream_data, StreamID, IsFin, Data}, Streams) ->
|
||||
ct:pal("WT handle ~p~n", [Event]),
|
||||
?LOG("WT handle ~p~n", [Event]),
|
||||
case Streams of
|
||||
#{StreamID := bidi} ->
|
||||
{[{send, StreamID, IsFin, Data}], Streams};
|
||||
|
@ -75,23 +83,23 @@ webtransport_handle(Event = {stream_data, StreamID, IsFin, Data}, Streams) ->
|
|||
{[{send, LocalStreamID, IsFin, Data}], Streams}
|
||||
end;
|
||||
webtransport_handle(Event = {datagram, Data}, Streams) ->
|
||||
ct:pal("WT handle ~p~n", [Event]),
|
||||
?LOG("WT handle ~p~n", [Event]),
|
||||
{[{send, datagram, Data}], Streams};
|
||||
webtransport_handle(Event = close_initiated, Streams) ->
|
||||
ct:pal("WT handle ~p~n", [Event]),
|
||||
?LOG("WT handle ~p~n", [Event]),
|
||||
{[{send, datagram, <<"TEST:close_initiated">>}], Streams};
|
||||
webtransport_handle(Event, Streams) ->
|
||||
ct:pal("WT handle ignore ~p~n", [Event]),
|
||||
?LOG("WT handle ignore ~p~n", [Event]),
|
||||
{[], Streams}.
|
||||
|
||||
webtransport_info({try_again, Event}, Streams) ->
|
||||
ct:pal("try_again ~p", [Event]),
|
||||
?LOG("WT try_again ~p", [Event]),
|
||||
webtransport_handle(Event, Streams).
|
||||
|
||||
terminate(Reason, Req, State=#{event_pid := EventPid}) ->
|
||||
ct:pal("terminate ~p ~p ~p", [Reason, Req, State]),
|
||||
?LOG("WT terminate ~p ~p ~p", [Reason, Req, State]),
|
||||
EventPid ! {'$wt_echo_h', terminate, Reason, Req, State},
|
||||
ok;
|
||||
terminate(Reason, Req, State) ->
|
||||
ct:pal("terminate ~p ~p ~p", [Reason, Req, State]),
|
||||
?LOG("WT terminate ~p ~p ~p", [Reason, Req, State]),
|
||||
ok.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue