当前位置: 技术问答>linux和unix
epoll et send 这样写有什么问题?
来源: 互联网 发布时间:2017-04-08
本文导语: BOOL CNetCore_TCPEPoll::NetCore_TCPEPoll_SendMsg(LPCTSTR lpszSendAddr,LPCTSTR lpszSendMsg,int nMsgLen) { NetCore_IsErrorOccur = FALSE; NETCORE_TCPEPOLL_CLIENT st_NetClient; memset(&st_NetClient,'',sizeof(st_NetClient)); //首先获取地址的SOCKET句柄 ...
BOOL CNetCore_TCPEPoll::NetCore_TCPEPoll_SendMsg(LPCTSTR lpszSendAddr,LPCTSTR lpszSendMsg,int nMsgLen)
{
NetCore_IsErrorOccur = FALSE;
NETCORE_TCPEPOLL_CLIENT st_NetClient;
memset(&st_NetClient,'',sizeof(st_NetClient));
//首先获取地址的SOCKET句柄
if (!NetCore_TCPEPoll_GetSocketForAddr(lpszSendAddr,&st_NetClient))
{
return FALSE;
}
int nSend = nMsgLen;
int nSendLeft = nMsgLen;
int nSendCount = 0;
while (TRUE)
{
if (!m_NetSocket.NetCore_Socket_Send(st_NetClient.m_Socket,&lpszSendMsg[nSendCount],&nSend))
{
if (ERROR_NETENGINE_NETCORE_SOCKET_SEND_LEN != NetCore_dwErrorCode)
{
return FALSE;
}
nSendCount += nSend;
nSendLeft -= nSend;
nSend = nSendLeft;
}
else
{
break;
}
}
ullFlowUp += nSendCount;
return TRUE;
}
BOOL CNetCore_Socket::NetCore_Socket_Send(SOCKET hSocket,LPCTSTR lpszSendMsg,int *pInt_MsgLen,int nTimedOut)
{
NetCore_IsErrorOccur = TRUE;
int nRet = 0;
if (SOCKET_ERROR == (nRet = send(hSocket,lpszSendMsg,size_t((*pInt_MsgLen)),0)))
{
if (EAGAIN == errno)
{
if (nTimedOut > 0)
{
Sleep(nTimedOut); //等待多少毫秒后使用迭代
return NetCore_Socket_Send(hSocket,lpszSendMsg,pInt_MsgLen,0);
}
NetCore_IsErrorOccur = TRUE;
NetCore_dwErrorCode = ERROR_NETENGINE_NETCORE_SOCKET_SEND_ISFULL;
return FALSE;
}
if (ECONNRESET == errno)
{
NetCore_IsErrorOccur = TRUE;
NetCore_dwErrorCode = ERROR_NETENGINE_NETCORE_SOCKET_SEND_ISCLOSED;
return FALSE;
}
NetCore_IsErrorOccur = TRUE;
NetCore_dwErrorCode = ERROR_NETENGINE_NETCORE_SOCKET_SEND_ISFAILED;
return FALSE;
}
if (nRet != *pInt_MsgLen)
{
NetCore_IsErrorOccur = TRUE;
NetCore_dwErrorCode = ERROR_NETENGINE_NETCORE_SOCKET_SEND_LEN;
return FALSE;
}
return TRUE;
}
我看到网上说要一直处理到send 返回 EAGAIN 才算OK,非阻塞的。不是在EPOLLOUT里面处理的发送 直接提取出来单独写的。
我要怎么处理EAGAIN 错误,在什么地方处理?
发送的时候就算返回大于0 对方有时候也是收不到的,我抓包看都没发出去。。。我发送哪儿做错了?
|
不要用ET。