iocp 代码如下:
void xIocpWorkThread::Execute(LPVOID lpParam)
{
DWORD dwNumberOfBytes = 0;
ULONG_PTR ulCompletionKey = 0;
IOCP_UNIT * pIocpunit = 0;
DWORD last_err = 0;
DWORD listener_addr = 0;
DWORD listener_sock = 0;
while( !xThread::IsTerminated() )
{
if( GetQueuedCompletionStatus(m_hIocp, &dwNumberOfBytes, &ulCompletionKey, (LPOVERLAPPED*)&pIocpunit, INFINITE ) )
{
pIocpunit->pUnit->OnComplete( dwNumberOfBytes, (DWORD)ulCompletionKey );
}
else
{
if( pIocpunit != NULL )
{
last_err = GetLastError();
xEventListener *pListener = pIocpunit->pUnit->getEventListener();
DWORD _puint_type = pIocpunit->pUnit->getType();
pIocpunit->pUnit->OnComplete( 0, 0 );
if(pListener != 0)
{
listener_addr = (DWORD)((void*)(pListener));
listener_sock = pListener->get_sock_fd();
}
LOG("GetQueuedCompletionStatus返回false, errno = %u, addr = %u, type = %u, sockfd = %u", last_err, listener_addr, _puint_type, listener_sock);
}
else
{
last_err = GetLastError();
LOG("GetQueuedCompletionStatus返回false, pIocpunit = null, errno = %u", last_err);
Sleep( 10 );
}
}
}
}
上面的函数在一个线程中运行,与逻辑线程不同。正常情况下是不会打印错误日志的,但是当游戏服务器运行的时候,收不到客户端消息,也不能给客户端发送消息,但是过了一会儿,服务器会自动恢复正常,可以接收消息,并且可以发送消息,当某个时间过去时,服务器无法发送消息和接收消息.....这种情况会定期发生,错误日志如下:
2011-09-13 04:48:41 GetQueuedCompletionStatus 返回false,errno = 64,addr = 227492836,type = 2,sockfd = 4294967295
2011-09-13 04:48:41 GetQueuedCompletionStatus 返回false,errno = 64,addr = 227492836,type = 2,sockfd = 4294967295
2011-09-13 04:48:41 GetQueuedCompletionStatus 返回false,errno = 64,addr = 227492836,type = 2,sockfd = 4294967295
...更多相同的...
2011-09-13 04:48:41 GetQueuedCompletionStatus 返回false,errno = 64,addr = 227492836,type = 2,sockfd = 4294967295
以上只是日志文件的一部分,可以看到,错误日志打印了这么多,错误号是64,socket描述符是4294967295(0xffffffff),打印错误日志的时候,服务器不能发消息,收不到消息。我想知道如何解决这个问题,谢谢!