日期:2014-05-16  浏览次数:20711 次

epoll et send 这样写有什么问题?

BOOL CNetCore_TCPEPoll::NetCore_TCPEPoll_SendMsg(LPCTSTR lpszSendAddr,LPCTSTR lpszSendMsg,int nMsgLen)
{
    NetCore_IsErrorOccur = FALSE;
    NETCORE_TCPEPOLL_CLIENT st_NetClient;
    memset(&st_NetClient,'\0',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;
        &nb