CreateIoCompletionPort函数是怎样和线程联系起来的??请熟悉完成端口模型的大虾执教。。
CompletionPort = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0,0);
GetSystemInfo(&SystemInfo);
SystemInfo.dwNumberOfProcessors);
for(i = 0; i < SystemInfo.dwNumberOfProcessors * 2; i++)
{
HANDLE ThreadHandle;
// Create a server worker thread and pass the completion port to the thread.
if ((ThreadHandle = CreateThread(NULL, 0, ServerWorkerThread, CompletionPort,0, &ThreadID)) == NULL) //---怎样把thead和CompletionPort 联系起来。??
// Close the thread handle
CloseHandle(ThreadHandle); ----为啥要关闭线程??
}
SOCKET Accept;
.....//略
CreateIoCompletionPort((HANDLE) Accept, CompletionPort, (DWORD) PerHandleData,
0);
------------------
问题如题。。。。
问题点数:20、回复次数:6Top
1 楼ciml(镜子)回复于 2001-12-07 14:35:42 得分 0
完成端口模型我概念都还没有,看《windows 网络编程技术》看不明白
你能讲讲你的理解吗?Top
2 楼ciml(镜子)回复于 2001-12-07 14:39:33 得分 0
另外,利用完成端口模型,是不是可以编写出高效的web服务器,邮件服务器了?Top
3 楼lwglucky(才鸟)回复于 2001-12-07 14:47:41 得分 0
关于性能:看msdn 文档
your application will have better performance if you create one thread per processor and build queues of requests for which the application maintains the context information. A thread would process all requests in a queue before processing requests in the next queue.
Top
4 楼lwglucky(才鸟)回复于 2001-12-07 15:55:05 得分 0
怕被冲走。Top
5 楼chinadreamer(我们需要梦想)回复于 2001-12-07 17:29:29 得分 20
CloseHandle(ThreadHandle); 只是关闭了线程对象的句柄,并没有关闭线程的运行.
CreateIoCompletionPort函数只是创建完成端口对象(CompletionPort = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0,0);)以及把套接字和完成端口对象关联起来(CreateIoCompletionPort((HANDLE) Accept, CompletionPort, (DWORD) PerHandleData,0);)
至于完成端口对象和线程的关联则是在你创建线程对象时(CreateThread(NULL, 0, ServerWorkerThread, CompletionPort,0, &ThreadID);)把完成端口对象的句柄传递给线程,这样在线程中就可以通过调用GetQueuedCompletionStatus函数来接受I/O完成的通知,接收和发送数据.
完成端口模型之所以高效是因为采用多线程的方式,可以充分利用多处理器以及网络协议的性能Top
6 楼lwglucky(才鸟)回复于 2001-12-08 20:57:45 得分 0
楼上的可以联系吗?/
oicq: 14465340Top




