diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2014-10-02 13:55:03 -0230 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2014-10-02 13:55:03 -0230 |
commit | 0217b84c777c7a6a3bff4efea52f23e704493d4b (patch) | |
tree | c305cffa9b6b39b81005b12e19321d35b5b6300e /cpp/src/Ice/ConnectionI.cpp | |
parent | Simplify Locator/Router finder usage in IceGridGUI (diff) | |
download | ice-0217b84c777c7a6a3bff4efea52f23e704493d4b.tar.bz2 ice-0217b84c777c7a6a3bff4efea52f23e704493d4b.tar.xz ice-0217b84c777c7a6a3bff4efea52f23e704493d4b.zip |
ICE-5585 call callback from ThreadPool if conneciton already closed
Diffstat (limited to 'cpp/src/Ice/ConnectionI.cpp')
-rw-r--r-- | cpp/src/Ice/ConnectionI.cpp | 73 |
1 files changed, 41 insertions, 32 deletions
diff --git a/cpp/src/Ice/ConnectionI.cpp b/cpp/src/Ice/ConnectionI.cpp index 6e807000c36..df2aef8affd 100644 --- a/cpp/src/Ice/ConnectionI.cpp +++ b/cpp/src/Ice/ConnectionI.cpp @@ -1177,36 +1177,58 @@ Ice::ConnectionI::flushAsyncBatchRequests(const BatchOutgoingAsyncPtr& outAsync) void Ice::ConnectionI::setCallback(const ConnectionCallbackPtr& callback) { - bool closed = false; { IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this); if(_state >= StateClosed) { - closed = true; - return; + if(callback) + { + class CallbackWorkItem : public DispatchWorkItem + { + public: + + CallbackWorkItem(const ConnectionIPtr& connection, const ConnectionCallbackPtr& callback) : + _connection(connection), + _callback(callback) + { + } + + virtual void run() + { + _connection->closeCallback(_callback); + } + + private: + + const ConnectionIPtr _connection; + const ConnectionCallbackPtr _callback; + }; + _threadPool->dispatch(new CallbackWorkItem(this, callback)); + } } else { _callback = callback; } } +} - if(closed && callback) +void +Ice::ConnectionI::closeCallback(const ConnectionCallbackPtr& callback) +{ + try { - try - { - callback->closed(this); - } - catch(const std::exception& ex) - { - Error out(_instance->initializationData().logger); - out << "connection callback exception:\n" << ex << '\n' << _desc; - } - catch(...) - { - Error out(_instance->initializationData().logger); - out << "connection callback exception:\nunknown c++ exception" << '\n' << _desc; - } + callback->closed(this); + } + catch(const std::exception& ex) + { + Error out(_instance->initializationData().logger); + out << "connection callback exception:\n" << ex << '\n' << _desc; + } + catch(...) + { + Error out(_instance->initializationData().logger); + out << "connection callback exception:\nunknown c++ exception" << '\n' << _desc; } } @@ -2178,20 +2200,7 @@ Ice::ConnectionI::finish() if(_callback) { - try - { - _callback->closed(this); - } - catch(const std::exception& ex) - { - Error out(_instance->initializationData().logger); - out << "connection callback exception:\n" << ex << '\n' << _desc; - } - catch(...) - { - Error out(_instance->initializationData().logger); - out << "connection callback exception:\nunknown c++ exception" << '\n' << _desc; - } + closeCallback(_callback); _callback = 0; } |