Пример #1
0
int EdStream::read(char *pBuf, int size)
{
    int ret = ::read(getfd(), pBuf, size);
    if (ret < size)
        resetRevent(POLLIN);
    if (!ret)
    {
        errno = ECONNRESET;
        return -1;
    }
    if ((ret == -1) && ((errno == EAGAIN) || (errno == EINTR)))
        return 0;
    return ret;
}
Пример #2
0
int EdStream::readv(struct iovec *vector, size_t count)
{
    int ret = ::readv(getfd(), vector, count);
    if (!ret)
    {
        errno = ECONNRESET;
        return -1;
    }
    if (ret == -1)
    {
        resetRevent(POLLIN);
        if ((errno == EAGAIN) || (errno == EINTR))
            return 0;
    }
    return ret;

}
Пример #3
0
int HttpListener::handleEvents( short event )
{
    static struct conn_data conns[CONN_BATCH_SIZE];
    static struct conn_data * pEnd = &conns[CONN_BATCH_SIZE];
    struct conn_data * pCur = conns;
    int allowed;
    int iCount = 0;
    ConnLimitCtrl * pCLC = HttpGlobals::getConnLimitCtrl();
    int limitType = 1;
    allowed = pCLC->availConn();
    if ( isSSL() )
    {
        if ( allowed > pCLC->availSSLConn() )
        {
            allowed = pCLC->availSSLConn();
            limitType = 2;
        }
    }

    while( iCount < allowed )
    {
        socklen_t len = 24;
        pCur->fd = accept( getfd(), (struct sockaddr *)(pCur->achPeerAddr), &len );
        if ( pCur->fd == -1 )
        {
            resetRevent( POLLIN );
            if (( errno != EAGAIN )&&( errno != ECONNABORTED )
                &&( errno != EINTR ))
            {
                LOG_ERR(( getLogger(),
                    "HttpListener::acceptConnection(): [%s] can't accept:%s!",
                    getAddrStr(), strerror( errno ) ));
            }
            break;
        }
        //++iCount;
        //addConnection( conns, &iCount );
        
        ++pCur;
        if ( pCur == pEnd )
        {
            iCount += CONN_BATCH_SIZE;
            batchAddConn( conns, pCur, &iCount );
            pCur = conns;
        }

    }
    if ( pCur > conns )
    {
        int n = pCur - conns;
        iCount += n;
        if ( n > 1 )
            batchAddConn( conns, pCur, &iCount );
        else
            addConnection( conns, &iCount );
    }
    if ( iCount > 0 )
    {
        m_pMapVHost->incRef( iCount );
        pCLC->incConn( iCount );
    }
    if ( iCount >= allowed )
    {
        if ( limitType == 1 )
        {
            if ( D_ENABLED( DL_MORE ) )
            {
                LOG_D(( getLogger(),
                    "[%s] max connections reached, suspend accepting!",
                    getAddrStr() ));
            }
            pCLC->suspendAll();
        }
        else
        {
            if ( D_ENABLED( DL_MORE ) )
            {
                LOG_D(( getLogger(),
                    "[%s] max SSL connections reached, suspend accepting!",
                    getAddrStr() ));
            }
            pCLC->suspendSSL();
        }
    }
    if ( D_ENABLED( DL_MORE ) )
    {
        LOG_D(( getLogger(),
            "[%s] %d connections accepted!", getAddrStr(), iCount ));
    }
    return 0;
}