diff options
author | Marc Laukien <marc@zeroc.com> | 2004-11-01 17:28:56 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2004-11-01 17:28:56 +0000 |
commit | 13bed028fb55ba1caeb4af15d1a18b1778a9e378 (patch) | |
tree | f2c9b11446bec453488d20249842962d396bb201 /cpp/src/Ice/IncomingAsync.cpp | |
parent | more glacier2 work (diff) | |
download | ice-13bed028fb55ba1caeb4af15d1a18b1778a9e378.tar.bz2 ice-13bed028fb55ba1caeb4af15d1a18b1778a9e378.tar.xz ice-13bed028fb55ba1caeb4af15d1a18b1778a9e378.zip |
AMD and dispatch exception handling fixes
Diffstat (limited to 'cpp/src/Ice/IncomingAsync.cpp')
-rw-r--r-- | cpp/src/Ice/IncomingAsync.cpp | 448 |
1 files changed, 274 insertions, 174 deletions
diff --git a/cpp/src/Ice/IncomingAsync.cpp b/cpp/src/Ice/IncomingAsync.cpp index 721c8912bcd..047696db2f9 100644 --- a/cpp/src/Ice/IncomingAsync.cpp +++ b/cpp/src/Ice/IncomingAsync.cpp @@ -28,7 +28,6 @@ void IceInternal::decRef(AMD_Object_ice_invoke* p) { p->__decRef(); } IceInternal::IncomingAsync::IncomingAsync(Incoming& in) : IncomingBase(in), - _finished(false), _instanceCopy(_os.instance()), _connectionCopy(_connection) { @@ -37,259 +36,361 @@ IceInternal::IncomingAsync::IncomingAsync(Incoming& in) : void IceInternal::IncomingAsync::__response(bool ok) { - assert(!_finished); - _finished = true; - - if(_response) + try { - _os.endWriteEncaps(); + if(_locator && _servant) + { + _locator->finished(_current, _servant, _cookie); + } - if(ok) + if(_response) { - *(_os.b.begin() + headerSize + 4) = static_cast<Byte>(DispatchOK); // Dispatch status position. + _os.endWriteEncaps(); + + if(ok) + { + *(_os.b.begin() + headerSize + 4) = static_cast<Byte>(DispatchOK); + } + else + { + *(_os.b.begin() + headerSize + 4) = static_cast<Byte>(DispatchUserException); + } + + _connection->sendResponse(&_os, _compress); } else { - *(_os.b.begin() + headerSize + 4) = static_cast<Byte>(DispatchUserException); // Dispatch status position. + _connection->sendNoResponse(); } } - - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); + catch(const LocalException& ex) + { + _connection->exception(ex); + } + catch(const std::exception& ex) + { + UnknownException uex(__FILE__, __LINE__); + uex.unknown = string("std::exception: ") + ex.what(); + _connection->exception(uex); + } + catch(...) + { + UnknownException uex(__FILE__, __LINE__); + uex.unknown = "unknown c++ exception"; + _connection->exception(uex); + } } void IceInternal::IncomingAsync::__exception(const Exception& exc) { - assert(!_finished); - _finished = true; - try { - exc.ice_throw(); - } - catch(RequestFailedException& ex) - { - if(ex.id.name.empty()) + if(_locator && _servant) { - ex.id = _current.id; + _locator->finished(_current, _servant, _cookie); } - - if(ex.facet.empty() && !_current.facet.empty()) + + try { - ex.facet = _current.facet; + exc.ice_throw(); } - - if(ex.operation.empty() && !_current.operation.empty()) + catch(RequestFailedException& ex) { - ex.operation = _current.operation; + if(ex.id.name.empty()) + { + ex.id = _current.id; + } + + if(ex.facet.empty() && !_current.facet.empty()) + { + ex.facet = _current.facet; + } + + if(ex.operation.empty() && !_current.operation.empty()) + { + ex.operation = _current.operation; + } + + if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 1) + { + __warning(ex); + } + + if(_response) + { + _os.endWriteEncaps(); + _os.b.resize(headerSize + 4); // Dispatch status position. + if(dynamic_cast<ObjectNotExistException*>(&ex)) + { + _os.write(static_cast<Byte>(DispatchObjectNotExist)); + } + else if(dynamic_cast<FacetNotExistException*>(&ex)) + { + _os.write(static_cast<Byte>(DispatchFacetNotExist)); + } + else if(dynamic_cast<OperationNotExistException*>(&ex)) + { + _os.write(static_cast<Byte>(DispatchOperationNotExist)); + } + else + { + assert(false); + } + + ex.id.__write(&_os); + + // + // For compatibility with the old FacetPath. + // + if(ex.facet.empty()) + { + _os.write(vector<string>()); + } + else + { + vector<string> facetPath; + facetPath.push_back(ex.facet); + _os.write(facetPath); + } + + _os.write(ex.operation); + + _connection->sendResponse(&_os, _compress); + } + else + { + _connection->sendNoResponse(); + } } - - if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 1) + catch(const UnknownLocalException& ex) { - __warning(ex); + if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } + + if(_response) + { + _os.endWriteEncaps(); + _os.b.resize(headerSize + 4); // Dispatch status position. + _os.write(static_cast<Byte>(DispatchUnknownLocalException)); + _os.write(ex.unknown); + _connection->sendResponse(&_os, _compress); + } + else + { + _connection->sendNoResponse(); + } } - - if(_response) + catch(const UnknownUserException& ex) { - _os.endWriteEncaps(); - _os.b.resize(headerSize + 4); // Dispatch status position. - if(dynamic_cast<ObjectNotExistException*>(&ex)) + if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) { - _os.write(static_cast<Byte>(DispatchObjectNotExist)); + __warning(ex); } - else if(dynamic_cast<FacetNotExistException*>(&ex)) + + if(_response) { - _os.write(static_cast<Byte>(DispatchFacetNotExist)); + _os.endWriteEncaps(); + _os.b.resize(headerSize + 4); // Dispatch status position. + _os.write(static_cast<Byte>(DispatchUnknownUserException)); + _os.write(ex.unknown); + _connection->sendResponse(&_os, _compress); } - else if(dynamic_cast<OperationNotExistException*>(&ex)) + else { - _os.write(static_cast<Byte>(DispatchOperationNotExist)); + _connection->sendNoResponse(); } - else + } + catch(const UnknownException& ex) + { + if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) { - assert(false); + __warning(ex); } - ex.id.__write(&_os); - - // - // For compatibility with the old FacetPath. - // - if(ex.facet.empty()) + if(_response) { - _os.write(vector<string>()); + _os.endWriteEncaps(); + _os.b.resize(headerSize + 4); // Dispatch status position. + _os.write(static_cast<Byte>(DispatchUnknownException)); + _os.write(ex.unknown); + _connection->sendResponse(&_os, _compress); } else { - vector<string> facetPath; - facetPath.push_back(ex.facet); - _os.write(facetPath); + _connection->sendNoResponse(); } - - _os.write(ex.operation); } - } - catch(const UnknownLocalException& ex) - { - if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + catch(const LocalException& ex) { - __warning(ex); - } + if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } - if(_response) - { - _os.endWriteEncaps(); - _os.b.resize(headerSize + 4); // Dispatch status position. - _os.write(static_cast<Byte>(DispatchUnknownLocalException)); - _os.write(ex.unknown); + if(_response) + { + _os.endWriteEncaps(); + _os.b.resize(headerSize + 4); // Dispatch status position. + _os.write(static_cast<Byte>(DispatchUnknownLocalException)); + ostringstream str; + str << ex; + _os.write(str.str()); + _connection->sendResponse(&_os, _compress); + } + else + { + _connection->sendNoResponse(); + } } - } - catch(const UnknownUserException& ex) - { - if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + catch(const UserException& ex) { - __warning(ex); - } + if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } - if(_response) - { - _os.endWriteEncaps(); - _os.b.resize(headerSize + 4); // Dispatch status position. - _os.write(static_cast<Byte>(DispatchUnknownUserException)); - _os.write(ex.unknown); + if(_response) + { + _os.endWriteEncaps(); + _os.b.resize(headerSize + 4); // Dispatch status position. + _os.write(static_cast<Byte>(DispatchUnknownUserException)); + ostringstream str; + str << ex; + _os.write(str.str()); + _connection->sendResponse(&_os, _compress); + } + else + { + _connection->sendNoResponse(); + } } - } - catch(const UnknownException& ex) - { - if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + catch(const Exception& ex) { - __warning(ex); - } + if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } - if(_response) - { - _os.endWriteEncaps(); - _os.b.resize(headerSize + 4); // Dispatch status position. - _os.write(static_cast<Byte>(DispatchUnknownException)); - _os.write(ex.unknown); + if(_response) + { + _os.endWriteEncaps(); + _os.b.resize(headerSize + 4); // Dispatch status position. + _os.write(static_cast<Byte>(DispatchUnknownException)); + ostringstream str; + str << ex; + _os.write(str.str()); + _connection->sendResponse(&_os, _compress); + } + else + { + _connection->sendNoResponse(); + } } } catch(const LocalException& ex) { - if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) - { - __warning(ex); - } - - if(_response) - { - _os.endWriteEncaps(); - _os.b.resize(headerSize + 4); // Dispatch status position. - _os.write(static_cast<Byte>(DispatchUnknownLocalException)); - ostringstream str; - str << ex; - _os.write(str.str()); - } + _connection->exception(ex); + } + catch(const std::exception& ex) + { + UnknownException uex(__FILE__, __LINE__); + uex.unknown = string("std::exception: ") + ex.what(); + _connection->exception(uex); } - catch(const UserException& ex) + catch(...) + { + UnknownException uex(__FILE__, __LINE__); + uex.unknown = "unknown c++ exception"; + _connection->exception(uex); + } +} + +void +IceInternal::IncomingAsync::__exception(const std::exception& ex) +{ + try { if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) { - __warning(ex); + __warning(string("std::exception: ") + ex.what()); } - + if(_response) { _os.endWriteEncaps(); _os.b.resize(headerSize + 4); // Dispatch status position. - _os.write(static_cast<Byte>(DispatchUnknownUserException)); + _os.write(static_cast<Byte>(DispatchUnknownException)); ostringstream str; - str << ex; + str << "std::exception: " << ex.what(); _os.write(str.str()); + _connection->sendResponse(&_os, _compress); } + else + { + _connection->sendNoResponse(); + } + } + catch(const LocalException& ex) + { + _connection->exception(ex); } - catch(const Exception& ex) + catch(const std::exception& ex) + { + UnknownException uex(__FILE__, __LINE__); + uex.unknown = string("std::exception: ") + ex.what(); + _connection->exception(uex); + } + catch(...) + { + UnknownException uex(__FILE__, __LINE__); + uex.unknown = "unknown c++ exception"; + _connection->exception(uex); + } +} + +void +IceInternal::IncomingAsync::__exception() +{ + try { if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) { - __warning(ex); + __warning("unknown c++ exception"); } - + if(_response) { _os.endWriteEncaps(); _os.b.resize(headerSize + 4); // Dispatch status position. _os.write(static_cast<Byte>(DispatchUnknownException)); - ostringstream str; - str << ex; - _os.write(str.str()); + string reason = "unknown c++ exception"; + _os.write(reason); + _connection->sendResponse(&_os, _compress); + } + else + { + _connection->sendNoResponse(); } } - - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); -} - -void -IceInternal::IncomingAsync::__exception(const std::exception& ex) -{ - assert(!_finished); - _finished = true; - - if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) - { - __warning(string("std::exception: ") + ex.what()); - } - - if(_response) + catch(const LocalException& ex) { - _os.endWriteEncaps(); - _os.b.resize(headerSize + 4); // Dispatch status position. - _os.write(static_cast<Byte>(DispatchUnknownException)); - ostringstream str; - str << "std::exception: " << ex.what(); - _os.write(str.str()); + _connection->exception(ex); } - - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); -} - -void -IceInternal::IncomingAsync::__exception() -{ - assert(!_finished); - _finished = true; - - if(_os.instance()->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + catch(const std::exception& ex) { - __warning("unknown c++ exception"); + UnknownException uex(__FILE__, __LINE__); + uex.unknown = string("std::exception: ") + ex.what(); + _connection->exception(uex); } - - if(_response) + catch(...) { - _os.endWriteEncaps(); - _os.b.resize(headerSize + 4); // Dispatch status position. - _os.write(static_cast<Byte>(DispatchUnknownException)); - string reason = "unknown c++ exception"; - _os.write(reason); + UnknownException uex(__FILE__, __LINE__); + uex.unknown = "unknown c++ exception"; + _connection->exception(uex); } - - // - // Must be called last, so that if an exception is raised, - // this function is definitely *not* called. - // - __finishInvoke(); } IceAsync::Ice::AMD_Object_ice_invoke::AMD_Object_ice_invoke(Incoming& in) : @@ -309,7 +410,6 @@ IceAsync::Ice::AMD_Object_ice_invoke::ice_response(bool ok, const vector<Byte>& __exception(ex); return; } - __response(ok); } |