summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Feuer <mfeuer@jaguarlandrover.com>2015-03-13 16:33:54 -0700
committerMagnus Feuer <mfeuer@jaguarlandrover.com>2015-03-13 16:33:54 -0700
commit61254c198376d114bb845aabe6a99dd52b58d4dd (patch)
treeead3375989b6762fadd910cd32ff45186b230b44
parent5e023c9fe2c9c3c279b3a01754219e83f18dd29a (diff)
downloadrvi_core-61254c198376d114bb845aabe6a99dd52b58d4dd.tar.gz
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.
-rw-r--r--components/data_link_bert_rpc/src/connection.erl16
1 files changed, 16 insertions, 0 deletions
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) ->