Permalink
Browse files

Add timeout argument for `erl_epmd:names`.

So far `erl_epmd:port_please` allowed to specify a third argument as the timeout of the operation.

This patch adds the same option also to `erl_epmd:names` function.

The update has been done in order to assist with enabling the overriding of the default
`erl_epmd` module behaviour, as described in the following email:
    http://erlang.org/pipermail/erlang-questions/2011-October/061975.html
  • Loading branch information...
cipriancraciun committed Oct 25, 2011
1 parent d37811c commit 9166a4e1aa592cc4c23126ed8ac089c2b74872ef
Showing with 15 additions and 12 deletions.
  1. +15 −12 lib/kernel/src/erl_epmd.erl
@@ -30,7 +30,7 @@
%% External exports
-export([start/0, start_link/0, stop/0, port_please/2,
- port_please/3, names/0, names/1,
+ port_please/3, names/0, names/1, names/2,
register_node/2, open/0, open/1, open/2]).
%% gen_server callbacks
@@ -80,12 +80,15 @@ names() ->
{ok, H} = inet:gethostname(),
names(H).
-names(HostName) when is_atom(HostName) ->
- get_names1(atom_to_list(HostName));
-names(HostName) when is_list(HostName) ->
- get_names1(HostName);
-names(EpmdAddr) ->
- get_names(EpmdAddr).
+names(HostName) ->
+ names(HostName, infinity).
+
+names(HostName, Timeout) when is_atom(HostName) ->
+ get_names1(atom_to_list(HostName), Timeout);
+names(HostName, Timeout) when is_list(HostName) ->
+ get_names1(HostName, Timeout);
+names(EpmdAddr, Timeout) ->
+ get_names(EpmdAddr, Timeout).
register_node(Name, PortNo) ->
@@ -406,18 +409,18 @@ to_string(S) when is_list(S) -> S.
%% Find names on epmd
%%
%%
-get_names(EpmdAddress) ->
- case open(EpmdAddress) of
+get_names(EpmdAddress, Timeout) ->
+ case open(EpmdAddress, Timeout) of
{ok, Socket} ->
do_get_names(Socket);
_Error ->
{error, address}
end.
-get_names1(HostName) ->
- case inet:gethostbyname(HostName) of
+get_names1(HostName, Timeout) ->
+ case inet:gethostbyname(HostName, inet, Timeout) of
{ok,{hostent, _Name, _ , _Af, _Size, [EpmdAddr | _]}} ->
- get_names(EpmdAddr);
+ get_names(EpmdAddr, Timeout);
Else ->
Else
end.

0 comments on commit 9166a4e

Please sign in to comment.