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


C++ Timestamp::isElapsed方法代码示例

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


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

示例1: tryLockImpl

bool MutexImpl::tryLockImpl(long milliseconds)
{
#if defined(POCO_HAVE_MUTEX_TIMEOUT)
    struct timespec abstime;
    struct timeval tv;
    gettimeofday(&tv, NULL);
    abstime.tv_sec  = tv.tv_sec + milliseconds / 1000;
    abstime.tv_nsec = tv.tv_usec*1000 + (milliseconds % 1000)*1000000;
    if (abstime.tv_nsec >= 1000000000)
    {
        abstime.tv_nsec -= 1000000000;
        abstime.tv_sec++;
    }
    int rc = pthread_mutex_timedlock(&_mutex, &abstime);
    if (rc == 0)
        return true;
    else if (rc == ETIMEDOUT)
        return false;
    else
        throw SystemException("cannot lock mutex");
#else
    const int sleepMillis = 5;
    Timestamp now;
    Timestamp::TimeDiff diff(Timestamp::TimeDiff(milliseconds)*1000);
    do
    {
        int rc = pthread_mutex_trylock(&_mutex);
        if (rc == 0)
            return true;
        else if (rc != EBUSY)
            throw SystemException("cannot lock mutex");
#if defined(POCO_VXWORKS)
        struct timespec ts;
        ts.tv_sec = 0;
        ts.tv_nsec = sleepMillis*1000000;
        nanosleep(&ts, NULL);

#else
        struct timeval tv;
        tv.tv_sec  = 0;
        tv.tv_usec = sleepMillis * 1000;
        select(0, NULL, NULL, NULL, &tv);
#endif
    }
    while (!now.isElapsed(diff));
    return false;
#endif
}
开发者ID:JerkWisdom,项目名称:zpublic,代码行数:48,代码来源:Mutex_POSIX.cpp

示例2: tryLockImpl

bool MutexImpl::tryLockImpl(long milliseconds)
{
	const int sleepMillis = 5;
	Timestamp now;
	Timestamp::TimeDiff diff(Timestamp::TimeDiff(milliseconds)*1000);

	do
	{
		try
		{
			if (tryLockImpl())
				return true;
		}
		catch (...)
		{
			throw SystemException("cannot lock mutex");
		}
		Sleep(sleepMillis);
	} while (!now.isElapsed(diff));
	return false;
}
开发者ID:cshnick,项目名称:CommunicationModel,代码行数:21,代码来源:Mutex_WINCE.cpp

示例3: run

void RTMFPServerEdge::run() {
	_serverSocket.connect(_serverAddress);
	sockets.add(_serverSocket,*this);

	_serverConnection.setEndPoint(_serverSocket,_serverAddress);

	NOTE("Wait RTMFP server %s successful connection...",_serverAddress.toString().c_str());

	Timestamp connectAttemptTime;	
	_serverConnection.connect(_publicAddress);

	bool terminate=false;

	while(running()) {
		if(!sockets.process(_timeout)) {
			if(connectAttemptTime.isElapsed(6000000)) {
				_serverConnection.connect(_publicAddress);
				connectAttemptTime.update();
			}
			continue;
		}
		if(_serverConnection.connected()) {
			NOTE("RTMFP server %s successful connection",_serverAddress.toString().c_str());
			RTMFPServer::run();
			_serverConnection.clear();
			if(_serverConnection.connected()) {
				// Exception in RTMFPServer::run OR a volontary stop
				_serverConnection.setEndPoint(_serverSocket,_serverAddress);
				_serverConnection.disconnect();
				break; 
			}
			NOTE("RTMFP server %s connection lost",_serverAddress.toString().c_str());
		}
	}
	_sendingEngine.clear();
	sockets.remove(_serverSocket);
	_serverSocket.close();
}
开发者ID:pong18,项目名称:Cumulus,代码行数:38,代码来源:RTMFPServerEdge.cpp

示例4: testDocument

    void testDocument(const std::string& document)
    {
        Timestamp documentStartTimestamp;

        URI uri(_app.getURL());

        Log::debug() << "Starting client for '" << document << "'" << Log::end;

        HTTPClientSession cs(uri.getHost(), uri.getPort());
        HTTPRequest request(HTTPRequest::HTTP_GET, "/ws");
        HTTPResponse response;
        WebSocket ws(cs, request, response);

        Condition cond;
        Mutex mutex;

        Thread thread;
        Output output(ws, cond, mutex);

        thread.start(output);

        sendTextFrame(ws, "loolclient " + GetProtocolVersion());

        if (document[0] == '/')
            sendTextFrame(ws, "load " + document);
        else
            sendTextFrame(ws, "load url=" + document);

        sendTextFrame(ws, "status");

        // Wait for the "status:" message
        mutex.lock();
        cond.wait(mutex);
        mutex.unlock();

        Log::debug() << "Got status, size=" << output._width << "x" << output._height << Log::end;

        int y = 0;
        const int DOCTILESIZE = 5000;

        std::uniform_int_distribution<> dis(0, 20);
        int extra = dis(_g);

        int requestCount = 0;

        // Exercise the server with this document for some minutes
        while (!documentStartTimestamp.isElapsed((20 + extra) * Timespan::SECONDS) && !clientDurationExceeded())
        {
            int x = 0;
            while (!documentStartTimestamp.isElapsed((20 + extra) * Timespan::SECONDS) && !clientDurationExceeded())
            {
                sendTextFrame(ws,
                              "tile part=0 width=256 height=256 "
                              "tileposx=" + std::to_string(x * DOCTILESIZE) + " "
                              "tileposy=" + std::to_string(y * DOCTILESIZE) + " "
                              "tilewidth=" + std::to_string(DOCTILESIZE) + " "
                              "tileheight=" + std::to_string(DOCTILESIZE));
                requestCount++;
                x = ((x + 1) % ((output._width-1)/DOCTILESIZE + 1));
                if (x == 0)
                    break;
            }
            y = ((y + 1) % ((output._height-1)/DOCTILESIZE + 1));
            Thread::sleep(50);
        }
        sendTextFrame(ws, "canceltiles");

        Thread::sleep(10000);

        Log::debug() << "Sent " << requestCount << " tile requests, shutting down client for '" << document << "'" << Log::end;

        ws.shutdown();
        thread.join();
    }
开发者ID:wanweihua,项目名称:online,代码行数:74,代码来源:LoadTest.cpp


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