gen_tcp:send/2 but not gen_tcp:send/3 (3rd arg = timeout)

Matthias Lang matthias@REDACTED
Thu Feb 6 16:39:33 CET 2003

Scott Lystig Fritchie writes:
 > gen_tcp:recv() comes in two flavors: gen_tcp:recv/2 (no timeout) and
 > gen_tcp:recv/3 (third argument = timeout).  But there doesn't appear
 > to be a version of gen_tcp:send() that includes a timeout.
 > Looking into prim_inet.erl, there is no ability to specify a timeout.
 > :-(  I was hoping for an undocumented feature.

There _is_ an undocumented feature which does more or less
what you want. You can specify a {send_timeout, N} in the socket
options, i.e. either when you create the socket or later:

    gen_tcp:connect(Host, Port, [{send_timeout, 0}])    

See also:

There's a catch or two, though. For a start, it's not documented, so
it's probably not included in any test suite. Second, the behaviour on
timeout is a little odd. IIRC, send-on-full-socket returns an error
the first time you call it, but not if you then call it again. I'm a
bit hazy about the details, in my case I just want to nuke clients
who can't keep up.


More information about the erlang-questions mailing list