[erlang-questions] Erlang-C port not working on some unix machines

Richard Evans <>
Tue Apr 3 13:08:52 CEST 2012

I am using the standard erlang-c port code as described in the
tutorial http://www.erlang.org/doc/tutorial/c_port.html#id63121 and in
Joe Armstrong's book.

On my macbook, the erlang code and c-code communicate happily using
write_exact and read_exact. (I have not touched any of that standard

But when running exactly the same code on a unix pdp machine, the
communication from c to erlang breaks down. Specifically, in the
server's loop:

loop(Port) ->
	{call, Caller, Msg} ->
	    Port ! {self(), {command, encode(Msg)}},
		{Port, {data, Data}} ->  <---- WE NEVER GET HERE !!!
		    Caller ! {complex, decode(Data)}
	stop ->
	    Port ! {self(), close},
		{Port, closed} ->
	{'EXIT', Port, Reason} ->

The c-code receives the encoded-message successfully from the erlang
code. The c-code then writes back a response using write_exact (in
this case, an extremely simple OK response with a two byte header).
But the erlang code never receives this message.

The c-code for writing the response is the standard code (write_cmd
and write_exact). I have not touched any of this standard code:

int write_exact(byte* buff, int len)
    assert(len < BUFF_SIZE);
    int i, wrote = 0;
        if ((i = (int)write(1, buff+wrote, len-wrote)) <= 0)
            return (i);
        wrote += i;
    } while (wrote < len);
    return len;

Debugging the c-side, the write() function gets called - but somehow
the erlang side never receives the message back from the port.

Do you guys know have any ideas what might be causing this message to
fail to get back from c to erlang in this case on this machine? (It
used to work on the very same pdp machine - and I haven't touched the
erlang code since it last worked). Could it be something to do with
permissions or something, preventing the write in write_exact from
actually writing anything? I am at a loss.


More information about the erlang-questions mailing list