协议调整,避免阻塞

This commit is contained in:
anlicheng 2026-07-01 21:06:37 +08:00
parent 4791b66086
commit c106302d99
4 changed files with 3 additions and 7 deletions

View File

@ -13,8 +13,8 @@
-define(SERVER, ?MODULE). -define(SERVER, ?MODULE).
-define(DEFAULT_LISTENER, 'relay_server/udp'). -define(DEFAULT_LISTENER, 'relay_server/udp').
-define(DEFAULT_LISTEN_ON, 16380). -define(DEFAULT_LISTEN_ON, 1443).
-define(DEFAULT_IDLE_TIMEOUT, 30000). -define(DEFAULT_IDLE_TIMEOUT, 60000).
-define(DEFAULT_CONNECT_TIMEOUT, 5000). -define(DEFAULT_CONNECT_TIMEOUT, 5000).
-define(DEFAULT_MAX_CONNECTIONS, 1024). -define(DEFAULT_MAX_CONNECTIONS, 1024).
-define(DEFAULT_UDP_OPTIONS, [binary, {reuseaddr, true}]). -define(DEFAULT_UDP_OPTIONS, [binary, {reuseaddr, true}]).

View File

@ -141,8 +141,6 @@ handle_open(StreamId, Payload, State = #state{streams = Streams, users = Users})
ok -> ok ->
start_stream(StreamId, Request, State); start_stream(StreamId, Request, State);
error -> error ->
logger:warning("UDP relay stream ~p authentication failed from ~s",
[StreamId, esockd:format(State#state.peer)]),
send_error(StreamId, <<"authentication failed">>, State), send_error(StreamId, <<"authentication failed">>, State),
State State
end; end;

View File

@ -95,8 +95,6 @@ code_change(_OldVsn, State, _Extra) ->
handle_continue(connect, State = #state{host = Host, port = Port, connect_timeout = ConnectTimeout}) -> handle_continue(connect, State = #state{host = Host, port = Port, connect_timeout = ConnectTimeout}) ->
case gen_tcp:connect(binary_to_list(Host), Port, ?TCP_OPTIONS(ConnectTimeout), ConnectTimeout) of case gen_tcp:connect(binary_to_list(Host), Port, ?TCP_OPTIONS(ConnectTimeout), ConnectTimeout) of
{ok, Socket} -> {ok, Socket} ->
logger:debug("UDP relay stream ~p opened to ~ts:~p",
[State#state.stream_id, Host, Port]),
case inet:setopts(Socket, [{active, once}]) of case inet:setopts(Socket, [{active, once}]) of
ok -> ok ->
notify_opened(State), notify_opened(State),

View File

@ -4,7 +4,7 @@
{enabled, true}, {enabled, true},
{listener, 'relay_server/udp'}, {listener, 'relay_server/udp'},
{listen_on, 1443}, {listen_on, 1443},
{idle_timeout, 30000}, {idle_timeout, 60000},
{connect_timeout, 5000}, {connect_timeout, 5000},
{max_connections, 1024}, {max_connections, 1024},
{udp_options, [binary, {reuseaddr, true}]} {udp_options, [binary, {reuseaddr, true}]}