[erlang-questions] inet / active once

Per Hedeland per@REDACTED
Fri Nov 17 01:45:17 CET 2006

Joost Yervante Damad <joost.damad@REDACTED> wrote:
>recently I've been playing with the erlang programming language, and I like 
>it. I wrote a few test servers, and I especially like the inet active once 
>mechanism for having automatically framed messages, even over a TCP 
>connection, in combination with the {packet, PacketType} option.

Hm, {packet, PacketType} provides framing, but this is orthogonal to
{active, false|once|true} - i.e you can have framing (if inet_drv
supports the framing you need) in any of those modes.

>I see now two possibilities, either I expand inet_drv.c to have a new package 
>type, or I use {active, false}, and implemented the message framing in 
>Is there another possibilty? What is the recommended aproach?

I'd agree with Klacke, don't touch inet_drv until you're sure that you
need to.:-) Also, read carefully the documentation for gen_tcp:recv() to
see how the semantics differ from Unix/Posix recv()/read(), which makes
it much more convenient to "implement" the framing in Erlang. I.e. you
recv() as many bytes as you need to find the length of the message, then
recv() that many bytes - you never get less than you asked for, and
inet_drv and the I/O system handles the buffering and
(non-)blocking/polling for you.

--Per Hedeland

More information about the erlang-questions mailing list