This is a IOCP encapsulates class with a piece of code does not understand
Int OIOCPNet: : PrepareSocket (int Mode, OBufferedSocket * pBuffSockOld)
{
BOOL bError;
OBufferedSocket * pBuffSock;
BError=0;
If (PREPARE_SOCKET_INIT==Mode
{
//Create a new buffered socket.
PBuffSock=CreateBufferedSocket (Mode, 0);
If (0==pBuffSock)
{
M_pEL - & gt; ErrLog (ERRLOC, "CreateBufferedSocket is failed.");
BError=1;
Goto ErrHand;
}
}
The else
{
PBuffSock=CreateBufferedSocket (Mode, pBuffSockOld);
If (0==pBuffSock)
{
M_pEL - & gt; ErrLog (ERRLOC, "CreateBufferedSocket is failed.");
BError=1;
Goto ErrHand;
}
}
If (RET_FAIL== SetInitialAcceptMode
(pBuffSock)){
M_pEL - & gt; ErrLog (ERRLOC, "SetInitialAcceptMode is failed.");
BError=1;
Goto ErrHand;
}
If (0== AssociateSocketWithCompletionPort (pBuffSock - & gt; Socket, m_hCompletionPort, (DWORD) pBuffSock))
{
M_pEL - & gt; ErrLog (ERRLOC, "AssociateSocketWithCompletionPort is failed. The Error Code=% d", GetLastError ());
BError=1;
Goto ErrHand;
}
ErrHand:
If (1==bError)
{
Return RET_FAIL;
}
Return RET_SUCCESS;
}//PrepareSocket () [/align]
This function is called in the main thread, and SetInitialAcceptMode function calls in the asynchronous function, accept and accept asynchronous function is the IO packet delivery, only by the GetQueuedCompletionStatus accept worker threads complete packet (client) is connected with the completion port binding,
Question is: accept function will return immediately, but the client does not necessarily immediately connect came up, but immediately call the code behind the AssociateSocketWithCompletionPort function (which encapsulates the only with the completion port binding function) with the completion port binding, rather than in a worker thread completed
Don't know whether I understand there is a problem, ask everybody to help solve??? Thank you very much!!!!!!!!!!