Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Winsock WSASend Question

Author
Message
Michael P
18
Years of Service
User Offline
Joined: 6th Mar 2006
Location: London (UK)
Posted: 26th Jan 2009 18:19
I've spent a while googling the answer to this question with no luck.

Can multiple WSASend operations be used with the same WSABUF simultaneously without any problems? Each WSASend needs its own WSAOVERLAPPED structure but it is not clear whether each send operation needs its own WSABUF.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Jan 2009 20:55
It's fairly clear - you fill a buffer with your data, fill out a WSABUF structure that refers to that buffer, then use the WSABUF structure in your WSASend function call. Then you leave the buffer totally alone until that send has completed (detected via an event handle). Only at that point can you do something else with the buffer (ie, free it, or reuse it).

It says all of that (in its own way) in the MSDN page for WSASend & WSAOVERLAPPED.

Michael P
18
Years of Service
User Offline
Joined: 6th Mar 2006
Location: London (UK)
Posted: 26th Jan 2009 21:43
I was thinking that if you queue up multiple overlapped send operations then each send operation will occur in sequence which means that in theory you should be able to queue up multiple send operations for the same WSABUF without problems; each send operation will be completed before the next is begun. So queuing up multiple send operations should be the same as WSASend -> wait for it to complete -> do another send -> and so on, except that you don't need to wait for completion.

I could be completely wrong though, what do you think?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Jan 2009 21:51
Yes, you are completely wrong

If you want multiple concurrent sends, you need a buffer for each one that is currently being carried out.

Quote: "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."

Once you've initiated a send (or receive) using the WSA functions, those buffers are completely out-of-bounds to you and your code until the send/receive has signalled that it has completed. Once it has completed, you are free to discard or reuse that buffer. Beware memory leaks though - it's still your responsibility to keep track of and free those buffers.

Michael P
18
Years of Service
User Offline
Joined: 6th Mar 2006
Location: London (UK)
Posted: 26th Jan 2009 23:21
Ah I see, thanks for your help
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 27th Jan 2009 03:52
Quote: "It says all of that (in its own way) in the MSDN page for WSASend & WSAOVERLAPPED."


Yeah, I think that's where the confusion lies.

MSDN is written with the viewpoint that the programmer already knows everything else but what he/she's looking up.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office

Login to post a reply

Server time is: 2024-09-30 17:35:18
Your offset time is: 2024-09-30 17:35:18