Hello,
Let me please ask you a question:
There are two functions, WSASend and GetQueuedCompletionStatus. Both functions take the WSAOVERLAPPED structure as one of the parameters, into which they[function] write "something" there.
In the case of WSASend and GetQueuedCompletionStatus, in structure WSAOVERLAPPED is written to the parameter WSAOVERLAPPED.InternalHigh - is the number of bytes that are supposedly sent at the moment by the WSASend function.
And here's the question:
for the GetQueuedCompletionStatus function - the second parameter is:
from MSDN:
lpNumberOfBytesTransferredA pointer to a variable that receives the number of bytes transferred in a completed I/O operation.
and the 4th parameter, as I already wrote above, is the WSAOVERLAPPED structure:
from MSDN:
A pointer to a variable that receives the address of the OVERLAPPED structure that was specified when the completed I/O operation was started.
Function GetQueuedCompletionStatus fills in the structure field WSAOVERLAPPED.InternalHigh - "the number of bytes transferred in a completed I/O operation."
BUT, why is the second parameter needed then?
Or why then transfer WSAOVERLAPPED in function GetQueuedCompletionStatus , if there is a second parameter, where GetQueuedCompletionStatus will write the - ""the number of bytes transferred in a completed I/O operation.""?
I'm confused.
int main()
{
///...
HANDLE My_handle_Create_IOCP = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, NULL, Number_Threads); //Create IOCP
my_WSASocketA = WSASocketA(ver_IP, my_type, my_protocol, NULL, 0, WSA_FLAG_OVERLAPPED); //Create Socket
CreateIoCompletionPort((HANDLE)my_SOCKET, My_handle_Create_IOCP, int_key, 0); //Bind Socket to IOCP
//.....
}
And processing function queues CompletionPort:
void My_func_CompletionPort(HANDLE iocp, std::vector<SOCKET>& my_SOCKET_vec_1D)
{
DWORD my_DWORD;
ULONG_PTR my_CompletionKey;
WSAOVERLAPPED* my_WSAOVERLAPPED_1;
while (1)
{
BOOL my_BOOL_GetQueuedCompletionStatus = GetQueuedCompletionStatus(iocp, &my_DWORD, &my_CompletionKey, &my_WSAOVERLAPPED_1, INFINITE);
if (my_BOOL_GetQueuedCompletionStatus == TRUE)
{
std::cout<<my_DWORD<<std::endl;
std::cout<<my_WSAOVERLAPPED_1->InternalHigh <<std::endl;
//my_DWORD and my_WSAOVERLAPPED_1->InternalHigh ------> the same values!!!!!!!!
}
}