AcceptEx返回FALSE而WSAGetLastError却返回0,叫小弟我情何以堪
AcceptEx返回FALSE而WSAGetLastError却返回0,叫我情何以堪!
代码如下:
------解决方案--------------------
前者false表示失败,后者0一定表示成功吗?
我没看这个api的文档,但应该有说明吧?
------解决方案--------------------
Code Description Name
0 The operation completed successfully. ERROR_SUCCESS
------解决方案--------------------
Note: The function pointer for the AcceptEx function must be obtained at run time by making a call to the WSAIoctl function with the SIO_GET_EXTENSION_FUNCTION_POINTER opcode specified. The input buffer passed to the WSAIoctl function must contain WSAID_ACCEPTEX, a globally unique identifier (GUID) whose value identifies the AcceptEx extension function. On success, the output returned by the WSAIoctl function contains a pointer to the AcceptEx function. The WSAID_ACCEPTEX GUID is defined in the Mswsock.h header file.
------解决方案--------------------
http://blog.csdn.net/visualeleven/article/details/6088590
这里有个使用的例子代码~
------解决方案--------------------
pHandleData->accSock = WSASocket(AF_INET,SOCK_STREAM,0,NULL,0,WSA_FLAG_OVERLAPPED);
这里改成:
pHandleData->accSock = WSASocket(AF_INET,SOCK_STREAM,IPPROTO_TCP,NULL,0,WSA_FLAG_OVERLAPPED);
试试吧。。。
代码如下:
- C/C++ code
BOOL CServer::PostAccept(CHandleData* pHandleData, CIoData *pIoData) { pIoData->OperationType = IO_TYPE_ACCEPT; DWORD dwBytesRecv = 0; pHandleData->accSock = WSASocket(AF_INET,SOCK_STREAM,0,NULL,0,WSA_FLAG_OVERLAPPED); BOOL b = AcceptEx(m_ListenSock, pHandleData->accSock, pIoData->szBuff, 0/*表示尽快建立连接,不等待数据*/, sizeof(sockaddr)+16, sizeof(sockaddr)+16, &dwBytesRecv, (LPOVERLAPPED)&pIoData); if(!b){ int err = WSAGetLastError(); if(err != WSA_IO_PENDING){ SetErrorString(_T("IO_TYPE_ACCEPT出错!")); return FALSE; } } pHandleData->pIOData = pIoData; return TRUE; }
------解决方案--------------------
前者false表示失败,后者0一定表示成功吗?
我没看这个api的文档,但应该有说明吧?
------解决方案--------------------
Code Description Name
0 The operation completed successfully. ERROR_SUCCESS
------解决方案--------------------
Note: The function pointer for the AcceptEx function must be obtained at run time by making a call to the WSAIoctl function with the SIO_GET_EXTENSION_FUNCTION_POINTER opcode specified. The input buffer passed to the WSAIoctl function must contain WSAID_ACCEPTEX, a globally unique identifier (GUID) whose value identifies the AcceptEx extension function. On success, the output returned by the WSAIoctl function contains a pointer to the AcceptEx function. The WSAID_ACCEPTEX GUID is defined in the Mswsock.h header file.
------解决方案--------------------
http://blog.csdn.net/visualeleven/article/details/6088590
这里有个使用的例子代码~
------解决方案--------------------
pHandleData->accSock = WSASocket(AF_INET,SOCK_STREAM,0,NULL,0,WSA_FLAG_OVERLAPPED);
这里改成:
pHandleData->accSock = WSASocket(AF_INET,SOCK_STREAM,IPPROTO_TCP,NULL,0,WSA_FLAG_OVERLAPPED);
试试吧。。。