diff options
author | Marc Laukien <marc@zeroc.com> | 2003-06-20 20:18:16 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2003-06-20 20:18:16 +0000 |
commit | a7ced2038deb8ba2e0fe0e85517906b9ebe75d03 (patch) | |
tree | c4fb2bcc5483fa18f61b6dc8c7ac22403e747ed0 /cpp/src/Ice/Application.cpp | |
parent | Fixed incorrect property setting for Glacier tracing. (diff) | |
download | ice-a7ced2038deb8ba2e0fe0e85517906b9ebe75d03.tar.bz2 ice-a7ced2038deb8ba2e0fe0e85517906b9ebe75d03.tar.xz ice-a7ced2038deb8ba2e0fe0e85517906b9ebe75d03.zip |
added destroyOnInterrupt() to Application
Diffstat (limited to 'cpp/src/Ice/Application.cpp')
-rw-r--r-- | cpp/src/Ice/Application.cpp | 71 |
1 files changed, 68 insertions, 3 deletions
diff --git a/cpp/src/Ice/Application.cpp b/cpp/src/Ice/Application.cpp index b0d0268ceb8..455e7c2bb0d 100644 --- a/cpp/src/Ice/Application.cpp +++ b/cpp/src/Ice/Application.cpp @@ -63,6 +63,50 @@ static void holdInterruptCallback(int signal) } } +static void destroyOnInterruptCallback(int signal) +{ + if(_nohup && signal == SIGHUP) + { + return; + } + + { + StaticMutex::Lock lock(_mutex); + _interrupted = true; + } + + try + { + _communicator->destroy(); + } + catch(const IceUtil::Exception& ex) + { + cerr << _appName << " (while destroying in response to signal " << signal + << "): " << ex << endl; + } + catch(const std::exception& ex) + { + cerr << _appName << " (while destroying in response to signal " << signal + << "): std::exception: " << ex.what() << endl; + } + catch(const std::string& msg) + { + cerr << _appName << " (while destroying in response to signal " << signal + << "): " << msg << endl; + } + catch(const char * msg) + { + cerr << _appName << " (while destroying in response to signal " << signal + << "): " << msg << endl; + } + catch(...) + { + cerr << _appName << " (while destroying in response to signal " << signal + << "): unknown exception" << endl; + } +} + + static void shutdownOnInterruptCallback(int signal) { if(_nohup && signal == SIGHUP) @@ -151,13 +195,15 @@ Ice::Application::main(int argc, char* argv[], const char* configFile) _communicator = initialize(argc, argv); } - // Used by shutdownOnInterruptCallback + // + // Used by destroyOnInterruptCallback and shutdownOnInterruptCallback. // _nohup = (_communicator->getProperties()->getPropertyAsInt("Ice.Nohup") > 0); - // The default is to shutdown when a signal is received: // - shutdownOnInterrupt(); + // The default is to destroy when a signal is received. + // + destroyOnInterrupt(); status = run(argc, argv); } @@ -242,6 +288,25 @@ Ice::Application::communicator() } void +Ice::Application::destroyOnInterrupt() +{ + assert(_ctrlCHandler.get() != 0); + + StaticMutex::Lock lock(_mutex); + if(_ctrlCHandler->getCallback() == holdInterruptCallback) + { + _released = true; + _ctrlCHandler->setCallback(destroyOnInterruptCallback); + lock.release(); + _condVar->signal(); + } + else + { + _ctrlCHandler->setCallback(destroyOnInterruptCallback); + } +} + +void Ice::Application::shutdownOnInterrupt() { assert(_ctrlCHandler.get() != 0); |