当前位置: 首页>>代码示例>>C++>>正文


C++ Selectable::enabled方法代码示例

本文整理汇总了C++中Selectable::enabled方法的典型用法代码示例。如果您正苦于以下问题:C++ Selectable::enabled方法的具体用法?C++ Selectable::enabled怎么用?C++ Selectable::enabled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Selectable的用法示例。


在下文中一共展示了Selectable::enabled方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: waitUntil

bool SelectorImpl::waitUntil(Timespan until)
{
    if (!_avail.empty())
        until = Timespan(0);

    if (_isDirty)
    {
        _pollfds.clear();

        // recalculate size
        size_t pollSize= 1;

        std::set<Selectable*>::iterator iter;
        for( iter= _devices.begin(); iter != _devices.end(); ++iter)
        {
            if( (*iter)->enabled() )
                pollSize+= (*iter)->simpl().pollSize();
        }

        pollfd pfd;
        pfd.fd = -1;
        pfd.events = 0;
        pfd.revents = 0;

        _pollfds.assign(pollSize, pfd);

        // add entries
        pollfd* pCurr= &_pollfds[0];

        // insert event pipe
        pCurr->fd = _wakePipe[0];
        pCurr->events = POLLIN;

        ++pCurr;

        for( iter= _devices.begin(); iter != _devices.end(); ++iter)
        {
            if( (*iter)->enabled() )
            {
                const size_t availableSpace= &_pollfds.back() - pCurr + 1;
                size_t required = (*iter)->simpl().pollSize();
                assert( required <= availableSpace);
                pCurr+= (*iter)->simpl().initializePoll( pCurr, required);
            }
        }

        _isDirty= false;
    }

#ifdef HAVE_PPOLL
    struct timespec pollTimeout = { 0, 0 };
    struct timespec* pollTimeoutP = 0;
    if (until >= Timespan(0))
        pollTimeoutP = &pollTimeout;
#else
    int pollTimeout = until == Timespan(0) ? 0 : -1;
#endif

    int ret = -1;
    while (true)
    {
        if (until > Timespan(0))
        {
            Timespan remaining = until - Timespan::gettimeofday();
            if (remaining < Timespan(0))
                remaining = Timespan(0);

#ifdef HAVE_PPOLL
            pollTimeout.tv_sec = remaining.totalUSecs() / 1000000;
            pollTimeout.tv_nsec = (remaining.totalUSecs() % 1000000) * 1000;
#else
            if (Milliseconds(remaining) >= std::numeric_limits<int>::max())
                pollTimeout = std::numeric_limits<int>::max();
            else
                pollTimeout = Milliseconds(remaining).ceil();
#endif

            log_debug("remaining " << remaining);
        }
        else
            log_debug("no timeout");

#ifdef HAVE_PPOLL
        log_debug("ppoll with " << _pollfds.size() << " fds, timeout=" << pollTimeout.tv_sec << "s " << pollTimeout.tv_nsec << "ns");
        ret = ::ppoll(&_pollfds[0], _pollfds.size(), pollTimeoutP, 0);
        log_debug("ppoll returns " << ret);
#else
        log_debug("poll with " << _pollfds.size() << " fds, timeout=" << pollTimeout << "ms");
        ret = ::poll(&_pollfds[0], _pollfds.size(), pollTimeout);
        log_debug("poll returns " << ret);
#endif
        if( ret != -1 )
            break;

        if( errno != EINTR )
            throw IOError("Could not poll on file descriptors");

    }

    if( ret == 0 && _avail.empty() )
//.........这里部分代码省略.........
开发者ID:acklinr,项目名称:cxxtools,代码行数:101,代码来源:selectorimpl.cpp


注:本文中的Selectable::enabled方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。