From 61254c198376d114bb845aabe6a99dd52b58d4dd Mon Sep 17 00:00:00 2001 From: Magnus Feuer Date: Fri, 13 Mar 2015 16:33:54 -0700 Subject: Added tests to check if a connection to a remote node is still up. Used by ping management to see if we should reschedule the next ping. --- components/data_link_bert_rpc/src/connection.erl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/components/data_link_bert_rpc/src/connection.erl b/components/data_link_bert_rpc/src/connection.erl index aec31a8..7fd63cb 100644 --- a/components/data_link_bert_rpc/src/connection.erl +++ b/components/data_link_bert_rpc/src/connection.erl @@ -28,6 +28,8 @@ -export([setup/6]). -export([send/2]). -export([send/3]). +-export([is_connection_up/1]). +-export([is_connection_up/2]). -export([terminate_connection/1]). -export([terminate_connection/2]). @@ -84,6 +86,19 @@ terminate_connection(IP, Port) -> _Err -> {error, connection_not_found} end. + +is_connection_up(Pid) when is_pid(Pid) -> + is_process_alive(Pid). + +is_connection_up(IP, Port) -> + case connection_manager:find_connection_by_address(IP, Port) of + {ok, Pid} -> + is_connection_up(Pid); + + _Err -> + false + end. + %%%=================================================================== %%% gen_server callbacks %%%=================================================================== @@ -169,6 +184,7 @@ handle_cast({send, Data}, St) -> [ ?MODULE, Data]), gen_tcp:send(St#st.sock, term_to_binary(Data)), + {noreply, St}; handle_cast(_Msg, State) -> -- cgit v1.2.1