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

Richard Evans richardprideauxevans@REDACTED
Thu Apr 5 10:47:18 CEST 2012


If you guys have any pointers or suggestions or anything, I would be
very grateful.

On Tue, Apr 3, 2012 at 12:08 PM, Richard Evans
<richardprideauxevans@REDACTED> wrote:
> 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
> code).
>
> 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) ->
>    receive
>        {call, Caller, Msg} ->
>            Port ! {self(), {command, encode(Msg)}},
>            receive
>                {Port, {data, Data}} ->  <---- WE NEVER GET HERE !!!
>                    Caller ! {complex, decode(Data)}
>            end,
>            loop(Port);
>        stop ->
>            Port ! {self(), close},
>            receive
>                {Port, closed} ->
>                    exit(normal)
>            end;
>        {'EXIT', Port, Reason} ->
>            exit(port_terminated)
>    end.
>
> 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;
>    do
>    {
>        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.
>
> thanks,
> Richard



More information about the erlang-questions mailing list