Question

I am aware that i should provide each Wsasend/recv operation unique OVERLAPPED structure or buffer and keep them valid until GQCS notification. But i need a little clarification about WSABUF structure, should it be unique too, or i can reuse it like this:

....
WSABUF bufftoSend;

bufftoSend.buf=buffer1;
bufftoSend.len=40;
WSASend(Socket, &bufftoSend, 1,..., NULL);

bufftoSend.buf=buffer2;
bufftoSend.len=20;
WSASend(Socket, &bufftoSend, 1,..., NULL);

bufftoSend.buf=buffer3;
bufftoSend.len=30;
WSASend(Socket, &bufftoSend, 1,..., NULL);
....

?

thanks for help.

Was it helpful?

Solution

If this function is completed in an overlapped manner, it is the Winsock service provider's responsibility to capture the WSABUF structures before returning from this call. This enables applications to build stack-based WSABUF arrays pointed to by the lpBuffers parameter.

OTHER TIPS

From the MSDN docs for WSASend(), here.

lpBuffers [in]

A pointer to an array of WSABUF structures. Each WSABUF structure contains a pointer to a buffer and the length, in bytes, of the buffer. 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.

I make it part of the buffer itself, along with the OVERLAPPED structure...

However, later in the docs it also says:

If this function is completed in an overlapped manner, it is the Winsock service provider's responsibility to capture the WSABUF structures before returning from this call. This enables applications to build stack-based WSABUF arrays pointed to by the lpBuffers parameter.

So it's likely that the WSABUF structures themselves can be destroyed/reused immediately after the call and the first paragraph only refers to the contents of the WSABUF structure; i.e. the buffers themselves.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top