Reputation: 731
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).
Is there a way I can know if the WSASend()
operation has been completed without calling GetQueuedCompletionStatus()
?
Upvotes: 1
Views: 460
Reputation: 9629
You can use WSAGetOverlappedResult
to get the WSASend
progression:
/* size bytes to send */
WSASend(Sock, &aBuf, 1, NULL, 0, &overlap, NULL);
/* warning no test for error cases */
DWORD dummy;
DWORD sent;
do
{
/* Ask for the sending progression without waiting */
WSAGetOverlappedResult(Sock, &SendOverlapped, &sent, FALSE, &dummy);
/* to prevent too much CPU usage */
Sleep(15);
} while (size != sent);
Upvotes: 1
Reputation: 33716
you need bind own socket to system created IOCP as result when operation finished your callback will be called automatic. you have 2 options here:
use BindIoCompletionCallback
- this will be work from Windows
XP (really even from win2000)
use CreateThreadpoolIo
- work from Windows Vista
after you create socket by
SOCKET socket = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, 0, 0, WSA_FLAG_OVERLAPPED)
you need call BindIoCompletionCallback((HANDLE)socket, *,0)
or CreateThreadpoolIo((HANDLE)socket, *, 0, 0);
and all. you not need call GetQueuedCompletionStatus()
or wait at all
Upvotes: 2