Skip to content

Commit

Permalink
just log and shutdown cleanly in case of initial connection refused
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Linzberger committed Aug 28, 2012
1 parent 8d21311 commit c893fa0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/zeta_client.erl
Expand Up @@ -33,10 +33,15 @@ init([Host, Port]) ->
%% Open UDP on a random port
{ok, UDPSock} = gen_udp:open(0, [binary, {active,false}]),
%% Try to make a TCP connection
{ok, TCPSock} = gen_tcp:connect(Host, Port,
[binary, {active, false}],
5000),
{ok, #st{udp = UDPSock, tcp = TCPSock, host = Host, port = Port}}.
case gen_tcp:connect(Host, Port,
[binary, {active, false}],
5000) of
{ok, TCPSock} ->
{ok, #st{udp = UDPSock, tcp = TCPSock, host = Host, port = Port}};
{error, econnrefused} ->
error_logger:info_msg("zeta_client connection refused"),
{stop, {shutdown, econnrefused}}
end.

terminate(_Reason, #st{udp = UDPSock, tcp = TCPSock}) ->
case UDPSock of
Expand Down

0 comments on commit c893fa0

Please sign in to comment.