25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-22 17:28:25 +01:00

Support other socket modules for MQTT

This commit is contained in:
Evgeny Khramtsov 2019-04-23 16:22:27 +03:00
parent 5faae61bef
commit feb4c7f5e9

View File

@ -153,9 +153,10 @@ format_error(Reason) ->
%%%=================================================================== %%%===================================================================
init([SockMod, Socket, ListenOpts]) -> init([SockMod, Socket, ListenOpts]) ->
MaxSize = proplists:get_value(max_payload_size, ListenOpts, infinity), MaxSize = proplists:get_value(max_payload_size, ListenOpts, infinity),
SockMod1 = case proplists:get_bool(tls, ListenOpts) of SockMod1 = case {SockMod, proplists:get_bool(tls, ListenOpts)} of
true -> fast_tls; {gen_tcp, true} -> fast_tls;
false -> SockMod {gen_tcp, false} -> gen_tcp;
{_, _} -> SockMod
end, end,
State1 = #state{socket = {SockMod1, Socket}, State1 = #state{socket = {SockMod1, Socket},
id = p1_rand:uniform(65535), id = p1_rand:uniform(65535),
@ -190,14 +191,14 @@ handle_call(Request, From, State) ->
?WARNING_MSG("Got unexpected call from ~p: ~p", [From, Request]), ?WARNING_MSG("Got unexpected call from ~p: ~p", [From, Request]),
noreply(State). noreply(State).
handle_cast(accept, #state{socket = {_, TCPSock} = Socket} = State) -> handle_cast(accept, #state{socket = {_, Sock} = Socket} = State) ->
case inet:peername(TCPSock) of case peername(State) of
{ok, IPPort} -> {ok, IPPort} ->
State1 = State#state{peername = IPPort}, State1 = State#state{peername = IPPort},
case starttls(Socket) of case starttls(Socket) of
{ok, Socket1} -> {ok, Socket1} ->
State2 = State1#state{socket = Socket1}, State2 = State1#state{socket = Socket1},
handle_info({tcp, TCPSock, <<>>}, State2); handle_info({tcp, Sock, <<>>}, State2);
{error, Why} -> {error, Why} ->
stop(State1, Why) stop(State1, Why)
end; end;
@ -863,6 +864,13 @@ activate({SockMod, Sock} = Socket) ->
end, end,
check_sock_result(Socket, Res). check_sock_result(Socket, Res).
-spec peername(state()) -> {ok, peername()} | {error, socket_error_reason()}.
peername(#state{socket = {SockMod, Sock}}) ->
case SockMod of
gen_tcp -> inet:peername(Sock);
_ -> SockMod:peername(Sock)
end.
-spec disconnect(state(), error_reason()) -> state(). -spec disconnect(state(), error_reason()) -> state().
disconnect(#state{socket = {SockMod, Sock}} = State, Err) -> disconnect(#state{socket = {SockMod, Sock}} = State, Err) ->
State1 = case Err of State1 = case Err of