After associating a socket handle with a completion port, you can begin proces
sing I/O requests by posting overlapped send and receive requests on the socke
t handle. You can now start to rely on the completion port for I/O completion 
notification. Basically, the completion port model takes advantage of the Wind
ows overlapped I/O mechanism in which Winsock API calls such as WSASend and WS
ARecv return immediately when called. It is up to your application to retrieve
 the results of the calls at a later time through an OVERLAPPED structure. In 
the completion port model, this is accomplished by having one or more worker t
hreads wait on the completion port using the GetQueuedCompletionStatus functio
n, which is defined as

BOOL GetQueuedCompletionStatus(
    HANDLE CompletionPort, 
    LPDWORD lpNumberOfBytesTransferred, 
    PULONG_PTR lpCompletionKey, 
    LPOVERLAPPED * lpOverlapped, 
    DWORD dwMilliseconds
);
The CompletionPort parameter represents the completion port to wait on. The lp
NumberOfBytesTransferred parameter receives the number of bytes transferred af
ter a completed I/O operation, such as WSASend or WSARecv. The lpCompletionKey
 parameter returns per-handle data for the socket that was originally passed i
nto the CreateIoCompletionPort function. As we already mentioned, we recommend
 saving the socket handle in this key. The lpOverlapped parameter receives the
 WSAOVERLAPPED structure of the completed I/O operation. This is actually an i
mportant parameter because it can be used to retrieve per I/O�Coperation data,
 which we will describe shortly. The final parameter, dwMilliseconds, specifie
s the number of milliseconds that the caller is willing to wait for a completi
on packet to appear on the completion port. If you specify INFINITE, the call 
waits forever.


--

�� ��源:��泉������ http://bbs.sdu.edu.cn [FROM: 202.194.32.132]