我有完成端口的问题,我的基本模型是一个聊天室当收到一个消息的时候就全盘发出去(所有的客户端socket我都保存在一个list中)
当接收到一个send结束的消息后,投送一个recv,基本上可以正常工作,问题在于当某个socket推出的时候,他会收到很多的推出信息(也就是接受的字节数=0地完成通告),很烦,想了很多办法都不行,不知道该如何解决,
当接收到一个send结束的消息后,投送一个recv,基本上可以正常工作,问题在于当某个socket推出的时候,他会收到很多的推出信息(也就是接受的字节数=0地完成通告),很烦,想了很多办法都不行,不知道该如何解决,
应该是:IOCP负责指定接收数据或者发送数据的BUFFER。
实际的动作由系统完成。完成了通知IOCP WORK THREAD,安排下个任务IOCP应该是妈妈桑,小姐由系统自己安排。
妈妈桑=CPU个数
Main()
{
//建立柜台
CompletionPort=CreateIoCompletionPort()
//建立龟奴
CreateListenThread()
//建立妈妈桑小组
CreaWorkThread()
//确定小姐模块 }
ListenThread()
{
//建立龟奴
ListenSocket.Create()
//穿上本院的工作服
ListenSocket.Bind()
//侦察大门口
ListenSocket.Listen()
//迎进来一位客人,选择一个小姐
LadySocket=Accept()
//填写初步帐单
PerData=Malloc()
PerlData.LadySocket=LadySocket;
//给客户说:有事情找总台
CreateIoCompletionPort((HANDLE) LadySocket,CompletionPort)
PerData.WSABUF.Buf=房间号
PerData.WSABUF.Len=房间大小
PerlData.Status=开房
//做开房的准备
WasRecv(PerData->LadySocket, PerData,)
}
WorkThread()
{
//妈妈桑
while(!打烊)
{
//查询柜台有人来吗?
GetQueuedCompletionStatus()
//有客人走了
}
}
那位哥们接着写完。。
writing windows nt server application in mfc using io completion ports..........
Second, you will notice something strange in the AwaitCommunicationAttempt member function on the server side:
m_ol1.hEvent = ((HANDLE)((DWORD)m_hConnectEvent|0x1));The reason why we manipulate the handle this way is only because of the control flow in the sample server application: The I/O completion port that is associated with the named pipe is established before a client connects to the pipe, and that means that every asynchronous operation on the pipe, including a ConnectNamedPipe call (which is how AwaitCommunicationAttempt is implemented), will end up unblocking a thread. The way I code the I/O completion ports makes it undesirable to unblock a thread upon ConnectNamedPipe (in other words, the I/O completion ports only server I/O with the named pipes, not connection administration). As the documentation to GetQueuedCompletionStatus mentions, an application can prevent an asynchronous I/O operation from sending completion notifications to a completion port by setting the low-order bit of the event object.
.......