[From nobody Mon Mar 25 16:12:53 2013
From: &quot;Magnus Fr berg&quot; &lt;magnus@bluetail.com&gt;
Sender: &lt;owner-erlang-questions@erlang.org&gt;
To: &quot;Vance Shipley&quot; &lt;vances@motivity.ca&gt;
Cc: &lt;erlang-questions@erlang.org&gt;
References: &lt;000101bf0ba2$3bad64d0$0abdc5c0@desk.motivity.ca&gt;
Subject: Re: net_adm:names() failing
Date: Fri, 1 Oct 1999 01:54:30 -0500
Message-ID: &lt;37F45AA6.3C244213@bluetail.com&gt;
MIME-Version: 1.0
Content-Type: text/plain;
	charset=&quot;Windows-1252&quot;
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 4.51 [en] (X11; I; Linux 2.2.5-15 i686)
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
X-Accept-Language: en

Hi !

Vance Shipley wrote:
&gt; 
&gt; I seem to be having some problems with tcp on my Unixware
&gt; port.  I believe that I'm loosing messages when the socket
&gt; gets closed.  Anybody have any ideas?

I noticed the same some time ago (I think it was on SUSE linux) and made
some changes to erl_epmd.erl. Seems like it was after the latest open
source release though.

&gt; 
&gt; On my Unixware port I have a problem with net_adm:names()
&gt; returning {ok, []} at all times (not just using short host
&gt; names as I reported before).
&gt; 
&gt; Some debugging shows that in the module erl_epmd, in the
&gt; function do_get_names, the socket seems to be getting closed
&gt; before the return message is received.  In the receive loop
&gt; the {tcp, Socket, [P0,P1,P2,P3|T]} never gets called, just
&gt; the {tcp_closed, Socket}.
&gt; 

The problem is that we cant be sure about that the 4 bytes port header
arrives in the same tcp package. I send a fix I made right now (I
compiled it and it seems to work ok for me;-).

erl_epmd.erl:

do_get_names(Socket) -&gt;
    inet_tcp:send(Socket, [?int16(1),?EPMD_NAMES]),
    do_get_names(Socket, []).

do_get_names(Socket, PList) -&gt;
    receive
	{tcp, Socket, Bytes} -&gt;
	    case get_port(Bytes, PList) of
		{ok, ?erlang_daemon_port, T} -&gt;
		    names_loop(Socket, T, []);
		{more, PList1} -&gt;
		    do_get_names(Socket, PList1);
		_ -&gt;
		    close(Socket),
		    {error, address}
	    end;
	{tcp_closed, Socket} -&gt;
	    {ok, []}
    end.

get_port(Bytes, [P0,P1,P2,P3]) -&gt;
    {ok, ?u32(P0,P1,P2,P3), Bytes};
get_port([H|Bytes], PList) -&gt;
    get_port(Bytes, PList ++ [H]);
get_port([], PList) -&gt;
    {more, PList}.

Hope this was your case as well.

/Magnus
]