fix quic channel
This commit is contained in:
parent
a1e768695b
commit
ed0ad499dd
@ -213,7 +213,8 @@ handle_event(info, {frame, <<?PACKET_POLICY_REQUEST, Body/binary>>}, registered,
|
|||||||
rules = <<1, 80:16, 2, 9090:16>>
|
rules = <<1, 80:16, 2, 9090:16>>
|
||||||
}),
|
}),
|
||||||
quic_send(Stream, <<?PACKET_POLICY_REPLY, PolicyResponsePkt/binary>>)
|
quic_send(Stream, <<?PACKET_POLICY_REPLY, PolicyResponsePkt/binary>>)
|
||||||
end;
|
end,
|
||||||
|
keep_state_and_data;
|
||||||
|
|
||||||
handle_event(info, {frame, <<?PACKET_PING>>}, _StateName, State = #state{stream = Stream, ping_counter = PingCounter}) ->
|
handle_event(info, {frame, <<?PACKET_PING>>}, _StateName, State = #state{stream = Stream, ping_counter = PingCounter}) ->
|
||||||
quic_send(Stream, <<?PACKET_PONG>>),
|
quic_send(Stream, <<?PACKET_PONG>>),
|
||||||
@ -232,7 +233,7 @@ handle_event(info, {timeout, _, ping_ticker}, _, State = #state{client_id = Clie
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
%% 发送指令信息
|
%% 发送指令信息
|
||||||
handle_event(info, {send_event, EventType, Event}, registered, #state{stream = Stream, client_id = ClientId}) ->
|
handle_event(cast, {send_event, EventType, Event}, registered, #state{stream = Stream, client_id = ClientId}) ->
|
||||||
logger:debug("[sdlan_channel] client_id: ~p, will send eventType: ~p, event: ~p", [ClientId, EventType, Event]),
|
logger:debug("[sdlan_channel] client_id: ~p, will send eventType: ~p, event: ~p", [ClientId, EventType, Event]),
|
||||||
quic_send(Stream, <<?PACKET_EVENT, EventType, Event/binary>>),
|
quic_send(Stream, <<?PACKET_EVENT, EventType, Event/binary>>),
|
||||||
keep_state_and_data;
|
keep_state_and_data;
|
||||||
@ -264,7 +265,11 @@ handle_event(info, {quic_closed, Stream, _Props}, _StateName, State = #state{str
|
|||||||
{stop, connection_closed, State};
|
{stop, connection_closed, State};
|
||||||
|
|
||||||
handle_event(info, {'EXIT', _, _}, _StateName, State) ->
|
handle_event(info, {'EXIT', _, _}, _StateName, State) ->
|
||||||
{stop, connection_closed, State}.
|
{stop, connection_closed, State};
|
||||||
|
|
||||||
|
handle_event(EventType, Info, StateName, State) ->
|
||||||
|
logger:notice("[sdlan_quic_channel] state_name: ~p, event_type: ~p, info: ~p", [StateName, EventType, Info]),
|
||||||
|
{stop, normal, State}.
|
||||||
|
|
||||||
%% @private
|
%% @private
|
||||||
%% @doc This function is called by a gen_statem when it is about to
|
%% @doc This function is called by a gen_statem when it is about to
|
||||||
@ -314,4 +319,9 @@ rsa_encode(PlainText, RsaPubKey) when is_binary(PlainText) ->
|
|||||||
-spec quic_send(Stream :: quicer:stream_handle(), Packet :: binary()) -> no_return().
|
-spec quic_send(Stream :: quicer:stream_handle(), Packet :: binary()) -> no_return().
|
||||||
quic_send(Stream, Packet) when is_binary(Packet) ->
|
quic_send(Stream, Packet) when is_binary(Packet) ->
|
||||||
Len = byte_size(Packet),
|
Len = byte_size(Packet),
|
||||||
{ok, _} = quicer:send(Stream, <<Len:16, Packet/binary>>).
|
case quicer:send(Stream, <<Len:16, Packet/binary>>) of
|
||||||
|
{ok, _} ->
|
||||||
|
ok;
|
||||||
|
{error, Reason} ->
|
||||||
|
exit({quic_send_failed, Reason})
|
||||||
|
end.
|
||||||
Loading…
x
Reference in New Issue
Block a user