[erlang-questions] gen_tcp:send(Sock, SmallPacket) issue
Tue Jun 19 14:28:07 CEST 2007
Matthias Lang <matthias@REDACTED> wrote:
> > I noticed that, when I use gen_tcp:send to send a small packet from
> > one machine to another, gen_tcp:send immediately returns ok, even when
> > the connection between the two machines is gone.
>The TCP protocol does not guarantee that a call to 'send' will block
>until your data has actually arrived at the other end.
Actually, with the socket API (which is basically the only thing there
is), you're pretty much guaranteed that the call *won't* so block. This
is really the only sane way to do an interface to TCP, and in any case
there's nothing Erlang or the VM can do about it. What the socket API
*does* provide is the ability to block (and possibly report an error) on
close() of the socket, via the SO_LINGER socket option. This is actually
available for gen_tcp too, via the undocumented 'linger' option -
whether it really works I don't know.
>If you want different behaviour, you need to build it on top of TCP,
>one way would be as Christian suggested.
The standard way is of course to send an ack/confirmation as user data
*in the same TCP session* if you need it - I'd say that's what all
well-designed TCP-based protocols do.
More information about the erlang-questions