add sdlan_transport

This commit is contained in:
anlicheng 2026-05-26 15:24:51 +08:00
parent 94f0476dee
commit bed29d89da
5 changed files with 14 additions and 2 deletions

View File

@ -11,6 +11,7 @@
-include("sdlan_pb.hrl"). -include("sdlan_pb.hrl").
-behaviour(gen_statem). -behaviour(gen_statem).
-behaviour(sdlan_transport).
%% %%
-define(STREAM_ACTIVE_N, 100). -define(STREAM_ACTIVE_N, 100).

View File

@ -118,7 +118,7 @@ command(Pid, ReceiverPid, ClientId, SubCommand) when is_pid(Pid), is_pid(Receive
-spec wait_command_ack(Ref :: reference(), Timeout :: integer()) -> {error, timeout} | {ok, CommandAck :: #'SDLCommandAck'{}}. -spec wait_command_ack(Ref :: reference(), Timeout :: integer()) -> {error, timeout} | {ok, CommandAck :: #'SDLCommandAck'{}}.
wait_command_ack(Ref, Timeout) when is_reference(Ref), is_integer(Timeout) -> wait_command_ack(Ref, Timeout) when is_reference(Ref), is_integer(Timeout) ->
receive receive
{quic_command_ack, Ref, CommandAck} -> {command_ack, Ref, CommandAck} ->
{ok, CommandAck} {ok, CommandAck}
after Timeout -> after Timeout ->
{error, timeout} {error, timeout}

View File

@ -287,7 +287,7 @@ handle_frame(<<?PACKET_COMMAND_ACK, Body/binary>>, Session = #session{status = r
{{Ref, ReceiverPid}, RestPendingCommands} ?= maps:take(PktId, PendingCommands), {{Ref, ReceiverPid}, RestPendingCommands} ?= maps:take(PktId, PendingCommands),
case is_process_alive(ReceiverPid) of case is_process_alive(ReceiverPid) of
true -> true ->
ReceiverPid ! {quic_command_ack, Ref, CommandAck}; ReceiverPid ! {command_ack, Ref, CommandAck};
false -> false ->
ok ok
end, end,

10
src/sdlan_transport.erl Normal file
View File

@ -0,0 +1,10 @@
%%%-------------------------------------------------------------------
%%% @doc Behaviour for client transport modules.
%%% @end
%%%-------------------------------------------------------------------
-module(sdlan_transport).
-callback send_event(Pid :: pid(), Event :: binary()) -> ok.
-callback command(Pid :: pid(), Ref :: reference(), ReceiverPid :: pid(), SubCommand :: {Tag :: atom(), SubCommand :: any()}) -> ok.
-callback stop(Pid :: pid(), Reason :: term()) -> ok.
-callback debug_info(Pid :: pid()) -> map().

View File

@ -12,6 +12,7 @@
-behaviour(gen_statem). -behaviour(gen_statem).
-behaviour(ranch_protocol). -behaviour(ranch_protocol).
-behaviour(sdlan_transport).
%% Ranch protocol callback %% Ranch protocol callback
-export([start_link/4]). -export([start_link/4]).