Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Change `erl_epmd` functions `port_please` and `names` to send message…

…s to the `erl_epmd` registered process.

So far only `register_node` delegated work to the `gen_server` process registered under `erl_epmd`.
The other two functions were implemented in-line, which made impossible to override the default implementation.

This patch makes the following simple updates:
 * renames the in-line implementation as `do_port_please` and `do_names` respectively;
 * add `handle_call` clauses to handle the new messages `{port_please, ...}` and `{names, ...}`;
 * these new handlers `spawn_link` a background process that actually does the work and replies;
(All the changes were made by taking the example of `register_nodes`.)

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...
commit 05899c20c810b047c06984d5ae54d6b3b3191804 1 parent 9166a4e
Ciprian Dorin Craciun authored October 25, 2011

Showing 1 changed file with 43 additions and 13 deletions. Show diff stats Hide diff stats

  1. 56  lib/kernel/src/erl_epmd.erl
56  lib/kernel/src/erl_epmd.erl
@@ -68,12 +68,8 @@ stop() ->
68 68
 port_please(Node, Host) ->
69 69
   port_please(Node, Host, infinity).
70 70
 
71  
-port_please(Node,HostName, Timeout) when is_atom(HostName) ->
72  
-  get_port1(Node,atom_to_list(HostName), Timeout);
73  
-port_please(Node,HostName, Timeout) when is_list(HostName) ->
74  
-  get_port1(Node,HostName, Timeout);
75  
-port_please(Node, EpmdAddr, Timeout) ->
76  
-  get_port(Node, EpmdAddr, Timeout).
  71
+port_please(Node,HostName, Timeout) ->
  72
+  gen_server:call(erl_epmd, {port_please, Node, HostName, Timeout}, infinity).
77 73
 
78 74
 
79 75
 names() -> 
@@ -83,12 +79,8 @@ names() ->
83 79
 names(HostName) ->
84 80
   names(HostName, infinity).
85 81
 
86  
-names(HostName, Timeout) when is_atom(HostName) ->
87  
-  get_names1(atom_to_list(HostName), Timeout);
88  
-names(HostName, Timeout) when is_list(HostName) ->
89  
-  get_names1(HostName, Timeout);
90  
-names(EpmdAddr, Timeout) ->
91  
-  get_names(EpmdAddr, Timeout).
  82
+names(HostName, Timeout) ->
  83
+  gen_server:call(erl_epmd, {names, HostName, Timeout}, infinity).
92 84
 
93 85
 
94 86
 register_node(Name, PortNo) ->
@@ -105,7 +97,8 @@ init(_) ->
105 97
 	    
106 98
 %%----------------------------------------------------------------------
107 99
 
108  
--type calls() :: 'client_info_req' | 'stop' | {'register', term(), term()}.
  100
+-type calls() :: 'client_info_req' | 'stop' | {'register', term(), term()}
  101
+        | {'port_please', term(), term(), term()} | {'names', term(), term()}.
109 102
 
110 103
 -spec handle_call(calls(), term(), state()) ->
111 104
         {'reply', term(), state()} | {'stop', 'shutdown', 'ok', state()}.
@@ -126,6 +119,28 @@ handle_call({register, Name, PortNo}, _From, State) ->
126 119
 	    {reply, {error, already_registered}, State}
127 120
     end;
128 121
 
  122
+handle_call({port_please, Node, HostName, Timeout}, From, State) ->
  123
+    spawn_link(fun() ->
  124
+        case (catch do_port_please(Node, HostName, Timeout)) of
  125
+            {'EXIT', Reason} ->
  126
+                gen_server:reply(From, {error, Reason});
  127
+            Outcome ->
  128
+                gen_server:reply(From, Outcome)
  129
+        end
  130
+    end),
  131
+    {noreply, State};
  132
+
  133
+handle_call({names, HostName, Timeout}, From, State) ->
  134
+    spawn_link(fun() ->
  135
+        case (catch do_names(HostName, Timeout)) of
  136
+            {'EXIT', Reason} ->
  137
+                gen_server:reply(From, {error, Reason});
  138
+            Outcome ->
  139
+                gen_server:reply(From, Outcome)
  140
+        end
  141
+    end),
  142
+    {noreply, State};
  143
+
129 144
 handle_call(client_info_req, _From, State) ->
130 145
     Reply = {ok,{r4,State#state.name,State#state.port_no}},
131 146
     {reply, Reply, State};
@@ -275,6 +290,13 @@ wait_for_reg_reply(Socket, SoFar) ->
275 290
 %% Lookup a node "Name" at Host
276 291
 %%
277 292
 
  293
+do_port_please(Node,HostName, Timeout) when is_atom(HostName) ->
  294
+  get_port1(Node,atom_to_list(HostName), Timeout);
  295
+do_port_please(Node,HostName, Timeout) when is_list(HostName) ->
  296
+  get_port1(Node,HostName, Timeout);
  297
+do_port_please(Node, EpmdAddr, Timeout) ->
  298
+  get_port(Node, EpmdAddr, Timeout).
  299
+
278 300
 get_port(Node, EpmdAddress, Timeout) ->
279 301
     case open(EpmdAddress, Timeout) of
280 302
 	{ok, Socket} ->
@@ -409,6 +431,14 @@ to_string(S) when is_list(S) -> S.
409 431
 %% Find names on epmd
410 432
 %%
411 433
 %%
  434
+
  435
+do_names(HostName, Timeout) when is_atom(HostName) ->
  436
+  get_names1(atom_to_list(HostName), Timeout);
  437
+do_names(HostName, Timeout) when is_list(HostName) ->
  438
+  get_names1(HostName, Timeout);
  439
+do_names(EpmdAddr, Timeout) ->
  440
+  get_names(EpmdAddr, Timeout).
  441
+
412 442
 get_names(EpmdAddress, Timeout) ->
413 443
     case open(EpmdAddress, Timeout) of
414 444
 	{ok, Socket} ->

0 notes on commit 05899c2

Please sign in to comment.
Something went wrong with that request. Please try again.