Click to See Complete Forum and Search --> : Windows IOCP - WSASend(). Unclarity regarding the data buffers.


mikoil
August 25th, 2009, 09:39 PM
Hi!

Taken from
http://msdn.microsoft.com/en-us/library/ms742203%28VS.85%29.aspx
After reading the following two lines I'm a bit confused;

For a Winsock application, once the WSASend function is called, the system owns these buffers and the application may not access them. This array must remain valid for the duration of the send operation.

Data is copied from the buffer(s) into the transport's buffer.

See? The 2nd line tells me that the data is being copied to the transport's buffer, meaning, from what I understand, that the original buffer is free for manipulations.

On the other hand, the 1st line tells me that these buffer(s) that I've sent must be "valid", for the "duration of the send operation".
Define "valid" and "duration of the send operation"???

Again, if I understand right;
"valid" - Buffer cannot be allocated on the stack, otherwise when the function exits, this memory is no longer "valid". (variable scope).

"duration of the send operation" - Really not clear. Does this mean that I have to wait for the "write complete" completion port notification?

Please advise, thank you very much!

MikeAThon
September 10th, 2009, 11:49 AM
The data is indeed copied from your buffer into the transport's buffer, but you cannot determine when this will happen. All you know is that it will happen at some point in time after your call to WSASend and just before you receive notification (on your completion port) that the send has completed.

For this reason, your buffer must remain valid until you receive notification that WSASend has completed.

Mike

Mike