iocp错误,有时收不到消息
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,类型 = 2,sockfd = 4294967295
2011-09-13 04:48:41 GetQueuedCompletionStatus 返回 false,errno = 64,addr = 227492836,类型 = 2,sockfd = 4294967295
2011-09-13 04:48:41 GetQueuedCompletionStatusfalse, 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,套接字描述符是4294967295(0xffffffff),打印错误日志时,服务器无法发送消息,也无法接收消息。我想知道如何解决这个问题,谢谢您!
iocp code is below:
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 );
}
}
}
}
the function above is running in a thread, different from the logic thread. normally, the error log would not be printed, but when game server is running sometime, It can't receive client message, and can't send message to client too, but after a while, the server will auto become normally, and can receive message, and can send message, when sometime is past, the server can't send message and receive message..... this happens periodically, the error log is below:
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
... many more of the same ...
2011-09-13 04:48:41 GetQueuedCompletionStatus返回false, errno = 64, addr = 227492836, type = 2, sockfd = 4294967295
the above is only a part of log file, as you can see, the error log is printed so much, error number is 64, and the socket descriptor is 4294967295(0xffffffff), when the error log is printed, the server can't send message, can't recieve message. I want to know how to resolve this problem, thanks to you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一步,弄清楚 error = 64 告诉你什么。为此,请打开 WinError.h 并搜索 64 ...
结果是 ERROR_NETNAME_DELETED - 所以,您的连接很可能已经消失...
我不确定为什么您会收到这么多这样的连接,每个套接字上是否有大量待处理的操作?
Sleep() 是一个非常糟糕的主意......
Step one, work out what error = 64 is telling you. To do that open up WinError.h and do a search for 64 ...
The result is ERROR_NETNAME_DELETED - so, it's likely that your connection has gone away...
I'm not sure why you're getting so many of these, do you have a large number of pending operations on each socket?
The Sleep() is a really bad idea...