Message-ID: <4BPiJH$w5t@bbs.sdu.edu.cn>
Subject: Completion Ports and Overlapped I/O
Date: Sun, 28 Mar 2004 12:05:53 +0000
From: onek.bbs@bbs.sdu.edu.cn (�式�)
Path: news.cnusenet.org!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-cn.bbs.comp.lang.mbox.zip!archiver1.google.com!news1.google.com!news.glorb.com!news.moat.net!ctu-peer!news.nctu.edu.tw!netnews.csie.nctu.edu.tw!maily.cic.tsinghua.edu.cn!netnews.sdu.edu.cn!SDU
Newsgroups: cn.bbs.comp.lang
Organization: 泉������
X-Filename: Programming/M.1080475553.A
Xref: news.cnusenet.org cn.bbs.comp.lang:18076


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]