reapthread.cpp

来自「ICE-3.2 一个开源的中间件」· C++ 代码 · 共 80 行

CPP
80 行
字号
// **********************************************************************//// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.//// This copy of Ice is licensed to you under the terms described in the// ICE_LICENSE file included in this distribution.//// **********************************************************************#include <ReapThread.h>using namespace std;using namespace Demo;ReapThread::ReapThread() :    _timeout(IceUtil::Time::seconds(10)),    _terminated(false){}voidReapThread::run(){    Lock sync(*this);    while(!_terminated)    {        timedWait(_timeout);        if(!_terminated)        {            list<SessionProxyPair>::iterator p = _sessions.begin();            while(p != _sessions.end())            {                try                {                    //                    // Session destruction may take time in a                    // real-world example. Therefore the current time                    // is computed for each iteration.                    //                    if((IceUtil::Time::now() - p->session->timestamp()) > _timeout)                    {                        string name = p->proxy->getName();                        p->proxy->destroy();                        cout << "The session " << name << " has timed out." << endl;                        p = _sessions.erase(p);                    }                    else                    {                        ++p;                    }                }                catch(const Ice::ObjectNotExistException&)                {                    p = _sessions.erase(p);                }            }        }    }}voidReapThread::terminate(){    Lock sync(*this);    _terminated = true;    notify();    _sessions.clear();}voidReapThread::add(const SessionPrx& proxy, const SessionIPtr& session){    Lock sync(*this);    _sessions.push_back(SessionProxyPair(proxy, session));}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?