fix quic server
This commit is contained in:
parent
8a095a9b45
commit
2a8ead5f01
26
apps/sdlan/src/quic/quic_client.erl
Normal file
26
apps/sdlan/src/quic/quic_client.erl
Normal file
@ -0,0 +1,26 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @author anlicheng
|
||||
%%% @copyright (C) 2026, <COMPANY>
|
||||
%%% @doc
|
||||
%%%
|
||||
%%% @end
|
||||
%%% Created : 13. 2月 2026 12:46
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(quic_client).
|
||||
-author("anlicheng").
|
||||
|
||||
%% API
|
||||
-export([start/0]).
|
||||
-export([do_start/0]).
|
||||
|
||||
start() ->
|
||||
erlang:spawn(?MODULE, do_start, []).
|
||||
|
||||
do_start() ->
|
||||
Port = 1365,
|
||||
{ok, Conn} = quicer:connect("localhost", Port, [{alpn, ["punchnet/1.0"]}, {verify, none}], 5000),
|
||||
{ok, Stm} = quicer:start_stream(Conn, []),
|
||||
{ok, 4} = quicer:send(Stm, <<"ping">>),
|
||||
logger:debug("[quic_client] client send success"),
|
||||
receive {quic, <<"pong">>, Stm, _Props} -> ok end,
|
||||
ok = quicer:close_connection(Conn).
|
||||
@ -55,11 +55,11 @@ callback_mode() ->
|
||||
%% process message, this function is called.
|
||||
|
||||
handle_event(internal, do_init, initializing, State = #state{conn = Conn}) ->
|
||||
logger:debug("[sdlan_quic_channel] conn: ~p, do_init", [Conn]),
|
||||
case quicer:accept_stream(Conn, []) of
|
||||
{ok, Stream} ->
|
||||
logger:debug("[sdlan_quic_channel] get stream: ~p", [Stream]),
|
||||
{next_state, initialized, State#state{stream_handle = Stream}};
|
||||
{error, closed} ->
|
||||
{stop, connection_closed, State};
|
||||
{error, Reason} ->
|
||||
logger:error("accept stream failed: ~p", [Reason]),
|
||||
{stop, Reason, State}
|
||||
@ -67,7 +67,7 @@ handle_event(internal, do_init, initializing, State = #state{conn = Conn}) ->
|
||||
|
||||
%% 处理quicer相关的信息
|
||||
handle_event(info, {quic, Msg, Stream, _Props}, _StateName, State = #state{stream_handle = Stream}) ->
|
||||
logger:debug("[sdlan_quic_stream] get message: ~p", [Msg]),
|
||||
logger:debug("[sdlan_quic_channel] get message: ~p", [Msg]),
|
||||
{keep_state, State};
|
||||
|
||||
handle_event(info, {quic_closed, Stream, _Props}, _StateName, State = #state{conn = Conn, stream_handle = Stream}) ->
|
||||
|
||||
@ -35,10 +35,12 @@ init() ->
|
||||
loop_accept(L) ->
|
||||
case quicer:accept(L, [], infinity) of
|
||||
{ok, Conn} ->
|
||||
logger:debug("[sdlan_quic_server] accept a new connection: ~p", [Conn]),
|
||||
case quicer:handshake(Conn) of
|
||||
ok ->
|
||||
{ok, ChannelPid} = sdlan_quic_channel:start_link(Conn),
|
||||
quicer:controlling_process(Conn, ChannelPid),
|
||||
{ok, NConn} ->
|
||||
logger:debug("[sdlan_quic_server] conn: ~p, handshake success", [NConn]),
|
||||
{ok, ChannelPid} = sdlan_quic_channel:start_link(NConn),
|
||||
quicer:controlling_process(NConn, ChannelPid),
|
||||
loop_accept(L);
|
||||
{error, _} ->
|
||||
quicer:close_connection(Conn),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user