TCP WSASend Completion Criteria

I am unable to find the specification of what it means that a TCP WSASend call completes. Does the completion of a WSASend operation require that an ACK response be received?

This question is relevant for slower networks with a 200ms - 2s ping timeout. Will it take 200ms - 2s for the WSASend completion callback to be invoked (or whatever completion mechanism is used)? Or perhaps only on some packets will Windows wait for an ACK and consider the WSASend operation complete much faster for all other packets?

The exact behavior makes a big difference with regard to buffer life cycle management and in turn has a significant impact on performance (locking, allocation/deallocation, and reference counting).


WSASend does not guarantee the following:

  1. That the data was sent (it might have been buffered)
  2. That it was received (it might have been lost)
  3. That the receiving application processed it (the sender cannot ever know this by principle)

It does not require a round-trip. In fact, with nagling enabled small amounts of data are always buffered for 200ms hoping that the application will send more. WSASend must return quickly so that nagling has a chance to work.

If you require confirmation, change the application protocol so that you get a confirmation back. No other way to do it.

To clarify, even without nagling (TCP_NODELAY) you do not get an ACK for your send operation. It will be sent out to the network but the remote side does not know that it should ACK. TCP has no way to say "please ACK this data immediately". Data being sent does not mean it will ever be received. The network could drop a second after the data was pushed out to a black hole.

It's not documented. It will likely be different depending on whether you have turned off send buffering. However, you always need to pay attention to the potential time that it will take to get a WSASend() completion, especially if you're using asynchronous calls. See this article of mine for details.

You get a WSASend() completion when the TCP stack has finished with your buffer. If you have NOT turned off send buffering by setting SO_SNDBUF to zero then it likely means you will get a completion once the stack copies your data into its buffers. If you HAVE turned off send buffering then it likely means that you will get a completion once you get an ACK (simply because the stack should need your buffer for any potential retransmissions). However, it's not documented.

Need Your Help

Cocoa: create drop zone for files

cocoa drag-and-drop

I want to create a drag and drop zone (using an NSView) for ANY file in my cocoa app. How do I do it?

EGL working on Linux but not on Android

android android-emulator android-ndk opengl-es-2.0 egl

I have EGL/GLES 2.0 code, which I try to run on Linux (via Mesa) and Android (iOS to come). On Linux it works fine and renders like expected.