<div dir="ltr">Hi Ruben,<div><br></div><div>I think you're falling into a common trap re. TCP. On a lightly-loaded network, if you send a block of data on one host it typically arrives at the other end of the connection as one thing. In other words, calls to send() and recv() are one-to-one. In that situation adding NODELAY will (seem to) solve problems like the ones that you were seeing. However, it will all fall to pieces when you're running under load or there's congestion or some other kind of problem, as it's perfectly legitimate for packets to be combined and/or fragmented which breaks this one-to-one relationship on which the correctness of your program rests.</div><div><br></div><div>You _must_ treat data received over TCP as a continuous stream of bytes and not a sequence of discrete packets, and do things such as accounting for the case where your 4-byte length indicator is split across two packets so does not all arrive at once. If you don't, it will bite you at the very worst time, and will do so nondeterministically. This kind of thing is very hard to reproduce in a test environment.</div><div><br></div><div>There is nothing special about the DCC protocol that makes it immune from this effect.</div><div><br></div><div>Best wishes,</div><div><br></div><div>David</div><div><br></div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 14 July 2016 at 10:48, Ruben Astudillo <span dir="ltr"><<a href="mailto:ruben.astud@gmail.com" target="_blank">ruben.astud@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 13/07/16 14:54, Andrey Sverdlichenko wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
If you are lucky. They still may be merged by sender if retransmission<br>
occurs, or on receiving side, if receiver waits too long before reads, and<br>
this is up to OS scheduler to control.<br>
NDELAY option is used to improve interactive latency, it will not make TCP<br>
obey message boundaries.<br>
</blockquote>
<br></span>
You're right. But understanding a little better the problem maybe will<br>
clarify why NODELAY is a valid option. DCC is in parts a redundant<br>
protocol. When you connect, the senders gives you the file you want but<br>
for coherency reasons every once in a while you have to reply the current<br>
transfered size through the same socket. This was a mean of preserving<br>
consistency that is redundant by the same mechanisms implemented on TCP.<br>
>From the page[1] I am using to implement<br>
<br>
  ``client A sends blocks of data (usually 1-2 KB) and at every block awaits<br>
  confirmation from the client B, that when receiving a block should reply<br>
  4 bytes containing an positive number specifying the total size of the<br>
  file received up to that moment.<br>
<br>
  The transmission closes when the last acknowledge is received by client A.<br>
<br>
  The acknowledges were meant to include some sort of coherency check in<br>
  the transmission, but in fact no client can recover from an acknowledge<br>
  error/desync, all of them just close the connection declaring the<br>
  transfer as failed (the situation is even worse in fact, often<br>
  acknowledge errors aren't even detected!).<br>
<br>
  Since the packet-acknowledge round trip eats a lot of time, many clients<br>
  included the send-ahead feature; the client A does not wait for the<br>
  acknowledge of the first packet before sending the second one.''<br>
<br>
The last part explains why my download still succeded until half the size<br>
of the file. But no sending any reply (because the message is too little<br>
to send) is a failure of interactivity on the protocol, not of message<br>
boundaries (which specify that the reply is 4 byte in length).<br>
<br>
[1]: <a href="http://www.kvirc.net/doc/doc_dcc_connection.html" rel="noreferrer" target="_blank">http://www.kvirc.net/doc/doc_dcc_connection.html</a><br>
--<br>
-- Ruben Astudillo<div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</div></div></blockquote></div><br></div>