使用完成端口通信,服务端使用WSASend发送响应数据时,出现10014错误,显示参数错误,但是经过检验,所有参数都是正确的。实在找不出问题了,求助。
代码为响应IOWrite的函数。
DWORD ulFlags = MSG_PARTIAL;
DWORD dwByteSend;
pContext->m_WriteBuffer.Delete(dwIoSize);//dwIoSize为上次发送完的数据
if (pContext->m_WriteBuffer.GetBufferLen() == 0)
{
pContext->m_WriteBuffer.ClearBuffer();
SetEvent(pContext->m_hWriteComplete);//让其他线程可以投递写操作
return true;
}
else
{
OVERLAPPEDPLUS * pOverlap = new OVERLAPPEDPLUS(IOWrite); pContext->m_wsaOutBuffer.buf = (char*) pContext->m_WriteBuffer.GetBuffer();
pContext->m_wsaOutBuffer.len = pContext->m_WriteBuffer.GetBufferLen(); //数据发送处
int nRetVal = WSASend(pContext->m_Socket, 
&pContext->m_wsaOutBuffer,
1,
&dwByteSend, 
ulFlags,
&pOverlap->m_ol, 
NULL);
int nLastError = WSAGetLastError();
if ( nRetVal == SOCKET_ERROR && nLastError != WSA_IO_PENDING )
{
CString str;
str.Format("OnClientWriting IO ERROR:%d",WSAGetLastError());
MessageBox(m_pFrame->m_hWnd, str.GetBuffer(0), "断开", MB_OK);
RemoveClient( pContext, FALSE );
}
}

解决方案 »

  1.   

    10014错误
    WSAEFAULT  The lpBuffers, lpNumberOfBytesSent, lpOverlapped, or lpCompletionRoutine argument is not totally contained in a valid part of the user address space.  
    lz还是仔细检查一下这四个参数吧
      

  2.   

    int nRetVal = WSASend(pContext->m_Socket,
    &pContext->m_wsaOutBuffer,
    1,
    &dwByteSend,
    ulFlags,
    &pOverlap->m_ol,//这里有参数
    NULL); //这个参数是否能为空?
      

  3.   

    http://topic.csdn.net/t/20051011/17/4319761.html
      

  4.   


    这个和我那个不一样啊,我的是WSASend返回10014错误,而不是的WSARecv出现这个错误。