Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an equivalent to TCP_CORK in Winsock?

In many UNIX TCP implementations, a socket option TCP_CORK is provided which allows the caller to bypass Nagle's algorithm and explicitly specify when to send a physical packet. Is there an equivalent feature in Windows (Winsock)?

TCP_CORK (since Linux 2.2)

If set, don't send out partial frames. All queued partial frames are sent when the option is cleared again. This is useful for prepending headers before calling sendfile(2), or for throughput optimization. As currently implemented, there is a 200 millisecond ceiling on the time for which output is corked by TCP_CORK. If this ceiling is reached, then queued data is automatically transmitted. This option can be combined with TCP_NODELAY only since Linux 2.5.71. This option should not be used in code intended to be portable.

(I'm aware of TCP_NODELAY, but this isn't what I need; I still want multiple writes to be accumulated in the send buffer, and then trigger the TCP stack when I'm ready for it to send a physical packet.)

like image 861
TypeIA Avatar asked Dec 20 '22 17:12

TypeIA


1 Answers

FWIW I successfully use TCP_NODELAY to get TCP_CORK-style behavior. I do it like this:

  1. unset the TCP_NODELAY flag on the socket
  2. Call send() zero or more times to add your outgoing data into the Nagle-queue
  3. set the TCP_NODELAY flag on the socket
  4. call send() with the number-of-bytes argument set to zero, to force an immediate send of the Nagle-queued data

That works fine for me under Windows, MacOS/X, and Linux. (Note that under Linux the final zero-byte send() isn't necessary)

like image 196
Jeremy Friesner Avatar answered Feb 23 '23 07:02

Jeremy Friesner