net_adm:names() failing

Magnus Fröberg magnus@REDACTED
Fri Oct 1 08:54:30 CEST 1999


Hi !

Vance Shipley wrote:
> 
> I seem to be having some problems with tcp on my Unixware
> port.  I believe that I'm loosing messages when the socket
> 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.

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

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) ->
    inet_tcp:send(Socket, [?int16(1),?EPMD_NAMES]),
    do_get_names(Socket, []).

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

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

Hope this was your case as well.

/Magnus



More information about the erlang-questions mailing list