完成端口 WSASend 出现10014错误
使用完成端口通信,服务端使用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 );
}
}