6

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.)

asked Mar 1, 2014 at 16:44

2 Answers 2

10

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)

answered Mar 1, 2014 at 18:44
Sign up to request clarification or add additional context in comments.

3 Comments

Interesting... do you mean that the other way around though (unset, then set)? I'll definitely give this a try though, thanks!
Yes, that's what I meant. I'll fix the post :)
Based on Nagle's Algorithm, I believe you will still send the first write as a packet with NO_DELAY unset. And the next write will be sent when the first in ack'd or the MSS or window size is reached in there buffer.
3

There is no equivalent. The best you can do is gather your data pieces into your own buffer first, and then send the completed buffer to the socket when ready, and let Nagle handle the packets normally.

answered Mar 1, 2014 at 16:50

1 Comment

Thanks; I would still set TCP_NODELAY in that case to avoid Nagle and the possible 200 ms latency.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.