<div dir="ltr">On Tue, Sep 3, 2013 at 7:58 PM, Joey Adams <span dir="ltr">&lt;<a href="mailto:joeyadams3.14159@gmail.com" target="_blank">joeyadams3.14159@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="im">On Tue, Sep 3, 2013 at 6:56 PM, Simon Yarde <span dir="ltr">&lt;<a href="mailto:simonyarde@me.com" target="_blank">simonyarde@me.com</a>&gt;</span> wrote:<br>
</div><div class="gmail_extra"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="im">I&#39;m new to Haskell and have reached an impasse in understanding the behaviour of sockets.<br>

<br></div><div class="im">
The crux of my line of enquiry is this;  how can my application know when to pause in generating its chunked output if send doesn&#39;t block and the current non-blocking send behaviour apparently succeeds when the send buffer should be full?<br>


</div></blockquote><div><br></div><div>&#39;send&#39; will eventually block after enough &#39;send&#39;s without matching &#39;recv&#39;s.  As Brandon explains, there is more buffering going on than the send buffer.  In particular, the receiving host will accept segments until its buffer fills up.  TCP implements flow control (i.e. keeps the sender from flooding the receiver) by </div>
</div></div></div></blockquote><div><br></div><div>Also note that, if you&#39;re using TCP, Nagle&#39;s algorithm will be turned on unless you specifically turn it off; this is explicitly designed to avoid sending very short packets, by buffering them into larger packets in the kernel network stack up until some timeout or a minimum threshold size is reached. (Protocols such as ssh and telnet turn it off for interactivity.) And if you&#39;re using UDP, there&#39;s no flow control at all; while packets won&#39;t be aggregated á la Nagle, the network stacks on the sending and receiving ends can do pretty much whatever they want with the individual packets. And in either case the socket buffer size is only the &quot;last mile&quot;: there is no way to control what happens elsewhere, and in particular the interrupt-time received packet handling usually won&#39;t know even what socket is the target, much less what buffer size that socket has set.</div>
<div><br></div></div>-- <br><div dir="ltr"><div>brandon s allbery kf8nh                               sine nomine associates</div><div><a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a>                                  <a href="mailto:ballbery@sinenomine.net" target="_blank">ballbery@sinenomine.net</a></div>
<div>unix, openafs, kerberos, infrastructure, xmonad        <a href="http://sinenomine.net" target="_blank">http://sinenomine.net</a></div></div>
</div></div>