Is there an equivalent to TCP_CORK in Winsock?

后端 未结 2 1744
挽巷
挽巷 2021-01-06 11:09

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 pa

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-06 11:54

    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)

提交回复
热议问题