コード例 #1
0
ファイル: request.cpp プロジェクト: mengjacky/alcedo
int Request::forward(int serverId)
{

	EventReactor *reactor = conn_->getReactor();
	Connector *connector = reactor->getConnector(serverId);
	if(connector == NULL)
	{
		return NOT_MATCH_SERVER;	
	}

	Event *evt = new Event();
	evt->set_event(SEND_BACKEND_EVENT);
	evt->setHandler(connector);
	evt->arg = this;
	reactor->registerEvent(evt);
	return 0;	
}
コード例 #2
0
ファイル: devpoller.cpp プロジェクト: 52M/openlitespeed
int DevPoller::waitAndProcessEvents(int iTimeoutMilliSec)
{
    if (m_curChanges)
        if (applyChanges() == -1)
            return LS_FAIL;
    struct dvpoll dvp;
    dvp.dp_fds     = m_events;
    dvp.dp_nfds    = MAX_EVENTS;
    dvp.dp_timeout = iTimeoutMilliSec;
    int ret = ioctl(m_fdDP, DP_POLL, &dvp);
    if (ret > 0)
    {
        struct pollfd *pBegin = m_events;
        struct pollfd *pEnd   = &m_events[ret];
        for (; pBegin < pEnd; ++pBegin)
        {
            int fd = pBegin->fd;
            //LS_DBG_L( "DevPoller: fd: %d, revents: %hd", fd, pBegin->revents );
            if (fd > m_reactorIndex.getCapacity())
            {
                //LS_DBG_L( "DevPoller: overflow, remove fd: %d", fd );
                appendChange(fd, POLLREMOVE);
            }
            else
            {
                EventReactor *pReactor = m_reactorIndex.get(fd);
                //if ( !pReactor )
                //    LS_DBG_L( "DevPoller: pReactor is NULL, remove fd: %d", fd );
                if ((pReactor) && (pBegin->fd == pReactor->getfd()))
                {
                    pReactor->setRevent(pBegin->revents);
                    pReactor->handleEvents(pBegin->revents);
                }
                else
                {
                    //LS_DBG_L( "DevPoller: does not match, remove fd: %d", fd );
                    appendChange(fd, POLLREMOVE);
                }
            }
        }
    }
    return ret;

}
コード例 #3
0
ファイル: epoll.cpp プロジェクト: bizonix/openlitespeed
int epoll::reinit()
{
    struct epoll_event epevt;
    close( m_epfd );
    m_epfd = (syscall(__NR_epoll_create, m_reactorIndex.getCapacity() ));
    if ( m_epfd == -1 )
        return -1;
    epevt.data.u64 = 0;
    ::fcntl( m_epfd, F_SETFD, FD_CLOEXEC );
    int n = m_reactorIndex.getUsed();
    for( int i = 0; i < n; ++i )
    {
        EventReactor * pHandler = m_reactorIndex.get( i );
        if ( pHandler )
        {
            epevt.data.u64 = 0;
            epevt.data.fd = pHandler->getfd();
            epevt.events = pHandler->getEvents();
            //(syscall(__NR_epoll_ctl, m_epfd, EPOLL_CTL_ADD, epevt.data.fd, &epevt));
            epoll_ctl( m_epfd, EPOLL_CTL_ADD, epevt.data.fd, &epevt);
        }
    }
    return 0;
}
コード例 #4
0
ファイル: epoll.cpp プロジェクト: bizonix/openlitespeed
int epoll::waitAndProcessEvents( int iTimeoutMilliSec )
{
    //int ret = (syscall(__NR_epoll_wait, m_epfd, m_pResults, EPOLL_RESULT_MAX, iTimeoutMilliSec ));
    int ret = epoll_wait( m_epfd, m_pResults, EPOLL_RESULT_MAX, iTimeoutMilliSec );
    if ( ret <= 0 )
        return ret;
    if ( ret == 1 )
    {
        int fd = m_pResults->data.fd;
        EventReactor * pReactor = m_reactorIndex.get( fd );
        if ( pReactor && (pReactor->getfd() == fd ) )
        {
            if ( m_pResults->events & POLLHUP )
                pReactor->incHupCounter();
            pReactor->assignRevent( m_pResults->events );
            pReactor->handleEvents( m_pResults->events );
        }
        return 1;
    }
    //if ( ret > EPOLL_RESULT_MAX )
    //    ret = EPOLL_RESULT_MAX;
    int    problem_detected = 0;
    struct epoll_event * pEnd= m_pResults + ret;
    struct epoll_event * p = m_pResults;
    while( p < pEnd )
    {
        int fd = p->data.fd;
        EventReactor * pReactor = m_reactorIndex.get( fd );
        assert( p->events );
        if ( pReactor )
        {
            if ( pReactor->getfd() == fd )
            {
                pReactor->assignRevent( p->events );
            }
            else
            {
                p->data.fd = -1;
            }
        }
        else
        {
            //p->data.fd = -1;
            if (( s_loop_fd == -1 )||( s_loop_fd == fd ))
            {
                if ( s_loop_fd == -1 )
                {
                    s_loop_fd = fd;
                    s_loop_count = 0;
                }
                problem_detected = 1;
                ++s_loop_count;
                if ( s_loop_count == 10 )
                {
                    if ( p->events & (POLLHUP|POLLERR) )
                        close( fd );
                    else
                    {
                        struct epoll_event epevt;
                        memset( &epevt, 0, sizeof( struct epoll_event ) );
                        epevt.data.u64 = 0;
                        epevt.data.fd = fd;
                        epevt.events = 0;
                        (syscall(__NR_epoll_ctl, m_epfd, EPOLL_CTL_DEL, fd, &epevt ));
                        //LOG_WARN(( "[%d] Remove looping fd: %d, event: %d\n", getpid(), fd, p->events ));
                        ++s_problems;
                    }
                }
                else if ( s_loop_count >= 20 )
                {
                    //LOG_WARN(( "Looping fd: %d, event: %d\n", fd, p->events ));
                    assert( p->events );
                    problem_detected = 0;
                }
            }
        }
        ++p;
    }
    p = m_pResults;
    while( p < pEnd )
    {
        int fd = p->data.fd;
        if ( fd != -1 )
        {
            EventReactor * pReactor = m_reactorIndex.get( fd );
            if ( pReactor && (pReactor->getAssignedRevent() == (int)p->events ) )
            {
                if ( p->events & POLLHUP )
                    pReactor->incHupCounter();
                pReactor->handleEvents( p->events );
            }
        }
        ++p;
    }

    if ( !problem_detected && s_loop_count )
    {
        s_loop_fd = -1;
        s_loop_count = 0;
    }
    memset( m_pResults, 0, sizeof( struct epoll_event) * ret );
    return ret;
    
}