Socket通讯接收报错10054
缘由:因考虑ACE的可移植性平台,所以使用ACE来进行通讯。目前客户端与服务器端粘包时,客户端总是接收报错10054,经过csdn,微软自提供解决方案,在socket连接前,贴上以下代码即可规避10054。
----------------------------------
C/C++ code?DWORD dwBytesReturned=0; BOOL bNewBehavior=FALSE; DWORD status; status = WSAIoctl(PrimaryUDP, SIO_UDP_CONNRESET, &bNewBehavior, sizeof(bNewBehavior), NULL, 0, &dwBytesReturned, NULL, NULL); if (SOCKET_ERROR == status) { DWORD dwErr = WSAGetLastError(); if (WSAEWOULDBLOCK == dwErr) { // nothing to do return(FALSE); } else { printf("WSAIoctl(SIO_UDP_CONNRESET) Error: %d\\n", dwErr); return(FALSE); } }
----------------------------------
问题:因为本人是ACE新手,所以对于WSAIoctl函数的第1个参数不知如何填写,因为不知道如何找出ACE_SOCK_Stream内部的socket。原大虾们帮忙看看。
附使用代码:
----------------------------------
C/C++ code?ACE_SOCK_Stream *pSock = new ACE_SOCK_Stream(); DWORD dwBytesReturned=0; BOOL bNewBehavior=FALSE; DWORD status; status = WSAIoctl( pSock->get_handle() , SIO_UDP_CONNRESET, &bNewBehavior, sizeof(bNewBehavior), NULL, 0, &dwBytesReturned, NULL, NULL); if (SOCKET_ERROR == status) { DWORD dwErr = WSAGetLastError(); if (WSAEWOULDBLOCK == dwErr) { // nothing to do return NULL; } else { printf("WSAIoctl(SIO_UDP_CONNRESET) Error: %d\\n", dwErr); return NULL; } } if(!ConnSrv(pSock,_ipAddr,_port)) { delete pSock; pSock=NULL; _validateSign = false; delete[] recvbuf; recvbuf = NULL; LC_PubFunValue::setSysState(4, "1"); _cErrorCode = "APP0027"; response->setRetCode("APP0027"); return response; }
10054应该是阻塞吧,之后通过select中的参数可以判断什么时候可读
Connection reset by peer.
A existing connection was forcibly closed by the remote host. This normally results if the peer application on the remote host is suddenly stopped, the host is rebooted, or the remote host used a "hard close" (see setsockopt for more information on the SO_LINGER option on the remote socket.)