Skip to content

Commit

Permalink
feat(conn): peer_needs_streams of msquic2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhuyan committed Sep 18, 2023
1 parent 2c80417 commit 17549c9
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 27 deletions.
14 changes: 3 additions & 11 deletions c_src/quicer_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1355,20 +1355,12 @@ handle_connection_event_peer_needs_streams(
assert(QUIC_CONNECTION_EVENT_PEER_NEEDS_STREAMS == Event->Type);
assert(c_ctx->Connection);
ErlNifEnv *env = c_ctx->env;
/* reserved for the future upgrade
ERL_NIF_TERM props_name[] = { Event->PEER_NEEDS_STREAMS.Bidirectional ?
ATOM_BIDI_STREAMS : ATOM_UNIDI_STREAMS }; ERL_NIF_TERM props_value[] = {
enif_make_uint64(env, Event->PEER_NEEDS_STREAMS.StreamLimit) }; ERL_NIF_TERM
report = make_event_with_props(env, ATOM_PEER_NEEDS_STREAMS,
enif_make_resource(env, c_ctx),
props_name,
props_value,
1);
*/
ERL_NIF_TERM report = make_event(env,
ATOM_PEER_NEEDS_STREAMS,
enif_make_resource(env, c_ctx),
ATOM_UNDEFINED);
Event->PEER_NEEDS_STREAMS.Bidirectional
? ATOM_BIDI_STREAMS
: ATOM_UNIDI_STREAMS);

enif_send(NULL, &(c_ctx->owner->Pid), NULL, report);
return QUIC_STATUS_SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion docs/messages_to_owner.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ More streams are available due to flow control from the peer.

Peer wants to open more streams but cannot due to flow control
```erlang
{quic, peer_needs_streams, connection_handle(), undefined}
{quic, peer_needs_streams, connection_handle(), unidi_streams | bidi_streams}
```

### Ideal processor changed
Expand Down
2 changes: 1 addition & 1 deletion src/quicer_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ handle_info({quic, peer_needs_streams, C, Needs},
#{ conn := C
, callback := M
, callback_state := CbState} = State) ->
?tp_ignore_side_effects_in_prod(debug, #{module => ?MODULE, conn => C, event => peer_needs_streams}),
?tp_ignore_side_effects_in_prod(debug, #{module => ?MODULE, conn => C, event => peer_needs_streams, needs => Needs}),
default_cb_ret(M:peer_needs_streams(C, Needs, CbState), State);

handle_info({quic, connection_resumed, C, ResumeData},
Expand Down
2 changes: 1 addition & 1 deletion src/quicer_server_conn_callback.erl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ streams_available(_C, {BidirCnt, UnidirCnt}, S) ->
, peer_bidi_stream_count => BidirCnt}}.

%% @doc May integrate with App flow control
peer_needs_streams(_C, undefined, S) ->
peer_needs_streams(_C, _UnidiOrBidi, S) ->
{ok, S}.

connected(Conn, _Flags, #{ slow_start := false, stream_opts := SOpts
Expand Down
7 changes: 4 additions & 3 deletions test/example_server_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ local_address_changed(_C, _NewAddr, S) ->
streams_available(_C, {_BidirCnt, _UnidirCnt}, S) ->
{ok, S}.

peer_needs_streams(C, #{unidi_streams := Current}, S) ->
peer_needs_streams(C, unidi_streams, S) ->
{ok, Current} = quicer:getopt(C, param_conn_local_unidi_stream_count),
ok = quicer:setopt(C, param_conn_settings, #{peer_unidi_stream_count => Current + 1}),
{ok, S};
peer_needs_streams(C, #{bidi_streams := Current}, S) ->
ok = quicer:setopt(C, param_conn_settings, #{peer_bidi_stream_count => Current + 1}),
peer_needs_streams(_C, bidi_streams, S) ->
%% leave it for test case to unblock it, see tc_multi_streams_example_server_3
{ok, S};
%% for https://github.com/microsoft/msquic/issues/3120
peer_needs_streams(_C, undefined, S) ->
Expand Down
14 changes: 4 additions & 10 deletions test/quicer_snb_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1996,20 +1996,14 @@ tc_multi_streams_example_server_1(Config) ->
true = quicer:is_unidirectional(Flag),
Incoming
after 1000 ->
%%ct:fail("no incoming stream")
%% reenable the check when it is fixed.
%% https://github.com/microsoft/msquic/issues/3120
ok
ct:fail("no incoming stream")
end,
receive
{quic, Data, Stm3In, DFlag} ->
ct:pal("~p is received from ~p with flag: ~p", [Data, Stm3In, DFlag]),
?assertEqual(Data, <<"ping3">>)
after 1000 ->
%% ct:fail("no incoming data")
%% reenable the check when it is fixed.
%% https://github.com/microsoft/msquic/issues/3120
ok
ct:fail("no incoming data")
end,
quicer:async_shutdown_connection(Conn, ?QUIC_CONNECTION_SHUTDOWN_FLAG_NONE, 0),
receive
Expand All @@ -2020,7 +2014,7 @@ tc_multi_streams_example_server_1(Config) ->
end,
fun(_Result, Trace) ->
ct:pal("Trace is ~p", [Trace]),
?assertMatch([{pair, _, _}],
?assertMatch([{pair, _, _}, {pair, _, _}],
?find_pairs(
#{ ?snk_kind := debug
, event := handoff_stream
Expand All @@ -2033,7 +2027,7 @@ tc_multi_streams_example_server_1(Config) ->
, stream := _STREAM0
},
Trace)),
?assertMatch([{pair, _, _}],
?assertMatch([{pair, _, _}, {pair, _, _}],
?find_pairs( #{ ?snk_kind := debug
, event := handoff_stream
, module := quicer
Expand Down

0 comments on commit 17549c9

Please sign in to comment.