Please tell me what exactly is the dwMilliseconds parameter in GetQueuedCompletionStatus responsible for?
Yes, I understand that everything is written on MSDN: https://learn.microsoft.com/en-us/windows/win32/api/ioapiset/nf-ioapiset-getqueuedcompletionstatus
dwMilliseconds
The number of milliseconds that the caller is willing to wait for a completion packet to appear at the completion port. If a completion packet does not appear within the specified time, the function times out, returns FALSE, and sets *lpOverlapped to NULL.
If dwMilliseconds is INFINITE, the function will never time out...
But I cannot understand - "to wait for a completion packet to appear".
Suppose I called the WSARecv function, which puts a read task on the completion port, and I conditionally set dwMilliseconds == 1000 (ms). What does it mean in this case - "to wait for a completion packet to appear" ??
-This is the time from the moment of calling WSARecv to the moment when the FINISHED task appears in the completion port, which can be obtained using the function GetQueuedCompletionStatus ?
-Or is it the time between the call to the WSARecv function and the moment when the read task will be placed on the completion port?
I'm completely confused.
Suppose I called the WSARecv function, which puts a read task on the completion port...
This is where you are making a mistake. The WSARecv task itself (or any I/O task, for that matter) is not put on the IOCP at all. It is submitted to whatever driver will be handling the task. The socket (or other I/O object) is associated with the IOCP, so when the read task is finished, the driver will put the result of that task into the IOCP's queue for you to then retrieve with GetQueuedCompletionStatus()
. That is why it is called a completion packet - it is a data packet describing the completion of a task. You are waiting for a task result to appear in the IOCP queue.
and I conditionally set dwMilliseconds == 1000 (ms). What does it mean in this case - "to wait for a completion packet to appear" ??
-This is the time from the moment of calling BCAreq to the moment when the FINISHED task appears in the completion port, which can be obtained using the function GetQueuedCompletionStatus ?
-Or is it the time between the call to the WSARecvfunction and the moment when the read task will be placed on the completion port?
Neither. It is the time from the moment you enter GetQueuedCompletionStatus()
to the time that any result of any I/O task that is associated with the IOCP is made available to you to retrieve from the IOCP's queue. So, in this case, you are waiting up to 1sec max for any queued I/O result to be made available to you.