[erlang-questions] Unbuffered/blocking gen_tcp send

Per Hedeland per@REDACTED
Fri Apr 17 20:59:49 CEST 2009

Johnny Billquist <bqt@REDACTED> wrote:
>Magnus Henoch wrote:
>> Matthias Lang <matthias@REDACTED> writes:
>>> TCP has flow control, but it can't be controlled at the fine level you
>>> would like it to, i.e. down to whether a given "packet" has been
>>> received by an application at the other end or not.
>> Actually, it can.  The receiver acknowledges to the sender exactly which
>> bytes have been received.  However, I don't know of any TCP
>> implementation that makes that information available to the
>> programmer...
>Actually, no. The received ack information in TCP do not tell which 
>bytes have been received by the program at the other end, only that they 
>have arrived to the TCP stack at the other end. It means that they are 
>available for the program at the other end, but wether or not that 
>program actually have recevied them you can't tell.

Not to mention that while the ack gives the last byte successfully
received, you obviously don't ack every byte individually. And "delayed
ack" is standard/required functionality in TCP since forever. In
combination with Nagle, this means that if you send 100 bytes, you may
have to wait for an effective eternity before you see the ack.

But of course the standard Erlang slogan "add another process" applies
here too. Implementing a "block-until-received-send" abstraction on top
of gen_tcp by means of user-level acks should amount to one process and
on the order of 10 lines of code at each end.

On a more general note, it seems the discussions about gen_tcp/gen_udp
usage on this list generally involve people that either have absolutely
no idea how the underlying protocols work, or that delve into the most
obscure implementation details (I'll confess to being guilty of the
latter). Occasionally I wonder if Erlang/OTP makes IP networking too
easy - if you had to populate some weird record with carefully
byte-ordered data and call half a dozen obscure functions before any
data would travel over the net, maybe people would make some effort to
understand what they were doing.:-) (Or just copy someone else's
incantations as "pure gospel, no questions asked".:-)


More information about the erlang-questions mailing list