Edit:
This question is not necessary, as the WSASend()
function can inherently be used in a blocking mode, even if the socket has the overlapped attribute and is associated with a completion port. To use it in a blocking mode: just don't supply an overlapped structure or a completion routine when calling WSASend()
.
I want to make sure that when I send data, the function will only return when this data has been placed in the send buffer. So this is what I come up with (pseudo code):
void WSASend_Block(char *arr, int length)
{
OVERLAPPED overlapped;
overlapped.hEvent = someEvent;
int result = WSASend(arr, length, &overlapped);
while(true)
{
if (result == 0) // IO operation has been scheduled
{
wait(overlapped.hEvent, INFINITE); // block until data is placed into send buffer
break;
}
else
{
result = WSASend(arr, length, &overlapped);
}
}
}