|
68 | 68 |
|
69 | 69 | -type packet_id() :: 0..65535. % ?MAX_PACKET_ID |
70 | 70 |
|
| 71 | + |
71 | 72 | -record(state, { |
72 | 73 | protocol_version :: mqtt_packet_map:mqtt_version(), |
73 | 74 | pool :: atom(), |
74 | 75 | runtime :: atom(), |
75 | 76 | client_id :: binary(), |
76 | 77 | routing_id :: binary(), |
77 | 78 | user_context :: term(), |
78 | | - transport = undefined :: pid() | function() | undefined, |
| 79 | + transport = undefined :: mqtt_sessions:transport() | undefined, |
79 | 80 | connection_pid = undefined :: pid() | undefined, |
80 | 81 | is_session_present = false :: boolean(), |
81 | 82 | pending_connack = undefined :: term(), |
@@ -145,7 +146,7 @@ update_user_context(Pid, Fun) -> |
145 | 146 | {error, noproc} |
146 | 147 | end. |
147 | 148 |
|
148 | | --spec get_transport( pid() ) -> {ok, pid()} | {error, notransport | noproc}. |
| 149 | +-spec get_transport( pid() ) -> {ok, mqtt_sessions:transport()} | {error, notransport | noproc}. |
149 | 150 | get_transport(Pid) -> |
150 | 151 | try |
151 | 152 | gen_server:call(Pid, get_transport, infinity) |
@@ -230,8 +231,8 @@ handle_call({update_user_context, Fun}, _From, #state{ user_context = UserContex |
230 | 231 |
|
231 | 232 | handle_call(get_transport, _From, #state{ transport = undefined } = State) -> |
232 | 233 | {reply, {error, notransport}, State}; |
233 | | -handle_call(get_transport, _From, #state{ transport = TransportPid } = State) -> |
234 | | - {reply, {ok, TransportPid}, State}; |
| 234 | +handle_call(get_transport, _From, #state{ transport = Transport } = State) -> |
| 235 | + {reply, {ok, Transport}, State}; |
235 | 236 |
|
236 | 237 | handle_call({incoming_data, NewData, ConnectionPid}, _From, #state{ incoming_data = Data, connection_pid = ConnectionPid } = State) -> |
237 | 238 | Data1 = << Data/binary, NewData/binary >>, |
@@ -1030,7 +1031,9 @@ send_transport(Msg, #state{ transport = Pid }) when is_pid(Pid) -> |
1030 | 1031 | ok |
1031 | 1032 | end; |
1032 | 1033 | send_transport(Msg, #state{ transport = Fun }) when is_function(Fun) -> |
1033 | | - Fun(Msg). |
| 1034 | + Fun(Msg); |
| 1035 | +send_transport(Msg, #state{ transport = {M, F, A} }) -> |
| 1036 | + erlang:apply(M, F, [Msg | A]). |
1034 | 1037 |
|
1035 | 1038 |
|
1036 | 1039 | %% @doc Queue a message, extract, type, message expiry, and QoS |
|
0 commit comments