Note that there are some explanatory texts on larger screens.

plurals
  1. POFlush kernel's TCP buffer for `MSG_MORE`-flagged packets
    text
    copied!<p>send()'s <a href="http://linux.die.net/man/2/sendto" rel="nofollow noreferrer">man page</a> reveals the <code>MSG_MORE</code> flag which is asserted to act like <code>TCP_CORK</code>. I have a wrapper function around <code>send()</code>:</p> <pre><code>int SocketConnection_Write(SocketConnection *this, void *buf, int len) { errno = 0; int sent = send(this-&gt;fd, buf, len, MSG_NOSIGNAL); if (errno == EPIPE || errno == ENOTCONN) { throw(exc, &amp;SocketConnection_NotConnectedException); } else if (errno == ECONNRESET) { throw(exc, &amp;SocketConnection_ConnectionResetException); } else if (sent != len) { throw(exc, &amp;SocketConnection_LengthMismatchException); } return sent; } </code></pre> <p>Assuming I want to use the kernel buffer, I could go with <code>TCP_CORK</code>, enable whenever it is necessary and then disable it to flush the buffer. But on the other hand, thereby the need for an additional system call arises. Thus, the usage of <code>MSG_MORE</code> seems more appropriate to me. I'd simply change the above send() line to:</p> <pre><code>int sent = send(this-&gt;fd, buf, len, MSG_NOSIGNAL | MSG_MORE); </code></pre> <p>According to <a href="http://lwn.net/2001/0125/kernel.php3" rel="nofollow noreferrer">lwm.net</a>, packets will be flushed automatically if they are large enough:</p> <blockquote> <p>If an application sets that option on a socket, the kernel will not send out short packets. Instead, it will wait until enough data has shown up to fill a maximum-size packet, then send it. When TCP_CORK is turned off, any remaining data will go out on the wire.</p> </blockquote> <p>But this section only refers to <code>TCP_CORK</code>. Now, what is the proper way to flush <code>MSG_MORE</code> packets?</p> <p>I can only think of two possibilities:</p> <ol> <li>Call send() with an empty buffer and without <code>MSG_MORE</code> being set</li> <li>Re-apply the TCP_CORK option as described on <a href="http://www.google.com/search?q=cache:http://www.baus.net/on-tcp_cork?flav=print" rel="nofollow noreferrer">this</a> page</li> </ol> <p>Unfortunately the whole topic is very poorly documented and I couldn't find much on the Internet.</p> <p>I am also wondering how to check that everything works as expected? Obviously running the server through <code>strace</code> is not an option. So the simplest way would be to use <code>netcat</code> and then look at its <code>strace</code> output? Or will the kernel handle traffic transmitted over a loopback interface differently?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload