diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2005-07-18 12:12:35 +0000 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2005-07-18 12:12:35 +0000 |
commit | af03e941b11ea0e8fca91fcf2e2df8b4939223b8 (patch) | |
tree | d1e456324d16ce87ad82d3b5d5bd83ada79b3d24 /cpp/demo/Glacier2/chat/Client.cpp | |
parent | Fix (diff) | |
download | ice-af03e941b11ea0e8fca91fcf2e2df8b4939223b8.tar.bz2 ice-af03e941b11ea0e8fca91fcf2e2df8b4939223b8.tar.xz ice-af03e941b11ea0e8fca91fcf2e2df8b4939223b8.zip |
Added ping thread
Diffstat (limited to 'cpp/demo/Glacier2/chat/Client.cpp')
-rwxr-xr-x | cpp/demo/Glacier2/chat/Client.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/cpp/demo/Glacier2/chat/Client.cpp b/cpp/demo/Glacier2/chat/Client.cpp index 22c7cacd390..41678016a51 100755 --- a/cpp/demo/Glacier2/chat/Client.cpp +++ b/cpp/demo/Glacier2/chat/Client.cpp @@ -15,6 +15,55 @@ using namespace std; using namespace Ice; using namespace Demo; +class SessionPingThread : public IceUtil::Thread, public IceUtil::Monitor<IceUtil::Mutex> +{ +public: + + SessionPingThread(const Glacier2::SessionPrx& session) : + _session(session), + _timeout(IceUtil::Time::seconds(20)), + _destroy(false) + { + } + + virtual void + run() + { + Lock sync(*this); + while(!_destroy) + { + timedWait(_timeout); + if(_destroy) + { + break; + } + try + { + _session->ice_ping(); + } + catch(const Ice::Exception&) + { + break; + } + } + } + + void + destroy() + { + Lock sync(*this); + _destroy = true; + notify(); + } + +private: + + const Glacier2::SessionPrx _session; + const IceUtil::Time _timeout; + bool _destroy; +}; +typedef IceUtil::Handle<SessionPingThread> SessionPingThreadPtr; + class ChatCallbackI : public ChatCallback { public: @@ -75,6 +124,9 @@ public: } } + SessionPingThreadPtr ping = new SessionPingThread(session); + ping->start(); + string category = router->getServerProxy()->ice_getIdentity().category; Identity callbackReceiverIdent; callbackReceiverIdent.name = "callbackReceiver"; @@ -119,9 +171,16 @@ public: catch(const Exception& ex) { cerr << ex << endl; + + ping->destroy(); + ping->getThreadControl().join(); + return EXIT_FAILURE; } + ping->destroy(); + ping->getThreadControl().join(); + return EXIT_SUCCESS; } |