diff options
author | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2017-04-15 11:15:50 +0300 |
---|---|---|
committer | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2017-04-15 11:15:50 +0300 |
commit | c290b4284f86487958d760417261c2ec473f2989 (patch) | |
tree | d20cab7368edaabcf804e342e82e480d59329505 /src/xmpp_stream_out.erl | |
parent | Add Riak as session manager RAM backend (diff) |
Fix closing of outbound S2S connections
Diffstat (limited to 'src/xmpp_stream_out.erl')
-rw-r--r-- | src/xmpp_stream_out.erl | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/src/xmpp_stream_out.erl b/src/xmpp_stream_out.erl index c8a2fba1..af5c67c6 100644 --- a/src/xmpp_stream_out.erl +++ b/src/xmpp_stream_out.erl @@ -161,23 +161,17 @@ send(_, _) -> -spec close(pid()) -> ok; (state()) -> state(). -close(Ref) -> - close(Ref, closed). - --spec close(pid(), atom()) -> ok; - (state(), atom()) -> state(). -close(Pid, Reason) when is_pid(Pid) -> - cast(Pid, {close, Reason}); -close(#{owner := Owner} = State, Reason) when Owner == self() -> - case is_disconnected(State) of - true -> State; - false -> - _IgnoreState = close_socket(State), - process_stream_end({socket, Reason}, State) - end; -close(_, _) -> +close(Pid) when is_pid(Pid) -> + close(Pid, closed); +close(#{owner := Owner} = State) when Owner == self() -> + close_socket(State); +close(_) -> erlang:error(badarg). +-spec close(pid(), atom()) -> ok. +close(Pid, Reason) -> + cast(Pid, {close, Reason}). + -spec establish(state()) -> state(). establish(State) -> process_stream_established(State). @@ -306,7 +300,12 @@ handle_cast({send, Pkt}, State) -> handle_cast(stop, State) -> {stop, normal, State}; handle_cast({close, Reason}, State) -> - noreply(close(State, Reason)); + State1 = close_socket(State), + noreply( + case is_disconnected(State) of + true -> State1; + false -> process_stream_end({socket, Reason}, State) + end); handle_cast(Cast, #{mod := Mod} = State) -> noreply(try Mod:handle_cast(Cast, State) catch _:undef -> State |