When calling WSASend()
, I have to pass it a WSAOVERLAPPED
instance, and I cannot re-use this WSAOVERLAPPED
instance until the previous WSASend()
operation has been completed (i.e. when a completion packet has been placed in the completion port, and when I deque this completion packet I guess).
Based on this understanding, I have a WSAOVERLAPPED
instance associated with each socket in my application, and I also have a boolean variable (called is_sending_in_progress
).
Now let's say that I have a button that will send the string "hello"
when clicked to the other side.
Now when the user clicks on this button, I will check to see if is_sending_in_progress
is false
, and if it is false
, then I would call WSASend()
and then set is_sending_in_progress
to true, now when I call GetQueuedCompletionStatus()
to deque the completion packet, I set is_sending_in_progress
to false
. And if the user clicks on the button and is_sending_in_progress
was true
, then I would display a message box telling the user that he can't send anything right now until the previous send operation is completed.
Now I don't think that this is a good approach to handle the sending of data in IOCP, because the user would get this message box a lot (especially if the IOCP threads are busy and it would take them some time to set is_sending_in_progress
to false
).
So is there a better approach to handling the sending of data in IOCP, like having multiple WSAOVERLAPPED
instances for each socket, and using the WSAOVERLAPPED
instance available when calling WSASend()
?