[erlang-questions] gen_tcp:send(Sock, SmallPacket) issue

frank.lenaerts@REDACTED frank.lenaerts@REDACTED
Mon Jun 18 16:39:00 CEST 2007


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.


(1) host1 connects to host2

(2) host1 sends a small message to host2 % host1 doesn't wait for a
    reply; this works fine

(3) connection (not TCP connection) between host1 and host2 is broken
    % intermediate router is removed or so

(4) host1 sends another small message to host2 % the process doing the
    gen_tcp:send immediately gets an ok, continues, thinking that the
    packet will be delivered reliably to host2, but the message never
    reaches host2 (the connection between host1 and host2 is not
    re-established in time)

It seems as if gen_tcp:send forwards the packet to the TCP/IP stack
and immediately returns, leaving the TCP/IP stack responsible for the

What happens if this fails (after retransmissions etc.) and the higher
level protocol doesn't expect a response from the other side?

- Is there a way to let gen_tcp:send block so that it only returns ok
  if it is delivered (thus TCP wise ok) to the other side?

- If the above is not possible, is there a mechanism to be informed by
  the TCP/IP stack when the connection timed out?

I'm using R11B-2. I also checked the readme's of R11B-{3,4,5} but
gen_tcp:send doesn't seem to be changed.

I noticed that the manpage of gen_tcp changed i.e. the last example
uses send_timeout but, as gen_tcp immediately returns in my case, I
think that this will only be blocking with LargeBinaries (and/or slow
links) instead of a SmallPacket.

Kind regards,


More information about the erlang-questions mailing list