diff options
author | Marc Laukien <marc@zeroc.com> | 2004-02-16 20:28:30 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2004-02-16 20:28:30 +0000 |
commit | 23948cd6e11d1c059cbe2b56bbce49713b01e126 (patch) | |
tree | df0c68781f4d367ed2a7c8326633ed0a81bb927f /cpp/src | |
parent | file DescriptorVisitor.h was initially added on branch icepack_refactoring. (diff) | |
download | ice-23948cd6e11d1c059cbe2b56bbce49713b01e126.tar.bz2 ice-23948cd6e11d1c059cbe2b56bbce49713b01e126.tar.xz ice-23948cd6e11d1c059cbe2b56bbce49713b01e126.zip |
more AMI
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Ice/Connection.cpp | 52 | ||||
-rw-r--r-- | cpp/src/Ice/OutgoingAsync.cpp | 239 | ||||
-rw-r--r-- | cpp/src/Ice/Proxy.cpp | 3 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 9 |
4 files changed, 145 insertions, 158 deletions
diff --git a/cpp/src/Ice/Connection.cpp b/cpp/src/Ice/Connection.cpp index ace046a264d..e019c29d250 100644 --- a/cpp/src/Ice/Connection.cpp +++ b/cpp/src/Ice/Connection.cpp @@ -530,50 +530,33 @@ void IceInternal::Connection::sendAsyncRequest(BasicStream* os, const OutgoingAsyncPtr& out) { Int requestId; - auto_ptr<LocalException> exception; { IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this); if(_exception.get()) { - // - // __finished() is called outside the thread - // synchronization. See below. - // - exception = auto_ptr<LocalException>(dynamic_cast<LocalException*>(_exception->ice_clone())); + _exception->ice_throw(); } - else + + assert(_state > StateNotValidated); + assert(_state < StateClosing); + + requestId = _nextRequestId++; + if(requestId <= 0) { - assert(_state > StateNotValidated); - assert(_state < StateClosing); - + _nextRequestId = 1; requestId = _nextRequestId++; - if(requestId <= 0) - { - _nextRequestId = 1; - requestId = _nextRequestId++; - } - - assert(!_endpoint->datagram()); // Twoway requests cannot be datagrams, and async implies twoway. - _asyncRequestsHint = _asyncRequests.insert(_asyncRequests.end(), - pair<const Int, OutgoingAsyncPtr>(requestId, out)); - - if(_acmTimeout > 0) - { - _acmAbsoluteTimeout = IceUtil::Time::now() + IceUtil::Time::seconds(_acmTimeout); - } } - } - - // - // Exceptions for asynchronous messages must be handled outside - // the thread synchronization, so that nested calls are possible. - // - if(exception.get()) - { - out->__finished(*_exception.get()); - return; + + assert(!_endpoint->datagram()); // Twoway requests cannot be datagrams, and async implies twoway. + _asyncRequestsHint = _asyncRequests.insert(_asyncRequests.end(), + pair<const Int, OutgoingAsyncPtr>(requestId, out)); + + if(_acmTimeout > 0) + { + _acmAbsoluteTimeout = IceUtil::Time::now() + IceUtil::Time::seconds(_acmTimeout); + } } try @@ -653,6 +636,7 @@ IceInternal::Connection::sendAsyncRequest(BasicStream* os, const OutgoingAsyncPt IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this); setState(StateClosed, ex); assert(_exception.get()); + _exception->ice_throw(); } } diff --git a/cpp/src/Ice/OutgoingAsync.cpp b/cpp/src/Ice/OutgoingAsync.cpp index 612f0f0a916..8acf39d6a6c 100644 --- a/cpp/src/Ice/OutgoingAsync.cpp +++ b/cpp/src/Ice/OutgoingAsync.cpp @@ -34,22 +34,133 @@ void IceInternal::decRef(AMI_Object_ice_invoke* p) { p->__decRef(); } IceInternal::OutgoingAsync::OutgoingAsync() : __is(0), - __os(0), - __cnt(0) + __os(0) { } IceInternal::OutgoingAsync::~OutgoingAsync() { + assert(!_reference); assert(!_connection); assert(!__is); assert(!__os); } void -IceInternal::OutgoingAsync::__setup(const ReferencePtr& ref) +IceInternal::OutgoingAsync::__finished(const LocalException& exc) +{ + if(_reference->locatorInfo) + { + _reference->locatorInfo->clearObjectCache(_reference); + } + +/* + ProxyFactoryPtr proxyFactory = _reference->instance->proxyFactory(); + if(proxyFactory) + { + proxyFactory->checkRetryAfterException(ex, cnt); + } + else + { + ex.ice_throw(); // The communicator is already destroyed, so we cannot retry. + } +*/ + + try + { + ice_exception(exc); + } + catch(const Exception& ex) + { + warning(ex); + } + catch(const std::exception& ex) + { + warning(ex); + } + catch(...) + { + warning(); + } + + assert(_connection); + _connection->decProxyCount(); + _connection = 0; + + assert(__is); + delete __is; + __is = 0; + + assert(__os); + delete __os; + __os = 0; +} + +bool +IceInternal::OutgoingAsync::__timedOut() const +{ + if(_connection->timeout() >= 0) + { + return IceUtil::Time::now() >= _absoluteTimeout; + } + else + { + return false; + } +} + +void +IceInternal::OutgoingAsync::__prepare(const ReferencePtr& ref, const string& operation, OperationMode mode, + const Context& context) { - const_cast<ReferencePtr&>(_reference) = ref; + assert(!_reference); + _reference = ref; + + assert(!_connection); + _connection = _reference->getConnection(); + _connection->incProxyCount(); + + assert(!__is); + __is = new BasicStream(_reference->instance.get()); + + assert(!__os); + __os = new BasicStream(_reference->instance.get()); + + _connection->prepareRequest(__os); + _reference->identity.__write(__os); + __os->write(_reference->facet); + __os->write(operation); + __os->write(static_cast<Byte>(mode)); + __os->writeSize(Int(context.size())); + Context::const_iterator p; + for(p = context.begin(); p != context.end(); ++p) + { + __os->write(p->first); + __os->write(p->second); + } + + __os->startWriteEncaps(); +} + +void +IceInternal::OutgoingAsync::__send() +{ + if(_connection->timeout() >= 0) + { + _absoluteTimeout = IceUtil::Time::now() + IceUtil::Time::milliSeconds(_connection->timeout()); + } + + try + { + _connection->sendAsyncRequest(__os, this); + } + catch(const LocalException&) + { + // + // Twoway requests report exceptions using finished(). + // + assert(false); + } } void @@ -153,55 +264,8 @@ IceInternal::OutgoingAsync::__finished(BasicStream& is) warning(); } - assert(_connection); - _connection->decProxyCount(); - _connection = 0; - - assert(__is); - delete __is; - __is = 0; - - assert(__os); - delete __os; - __os = 0; -} - -void -IceInternal::OutgoingAsync::__finished(const LocalException& exc) -{ - if(_reference->locatorInfo) - { - _reference->locatorInfo->clearObjectCache(_reference); - } - -/* - ProxyFactoryPtr proxyFactory = _reference->instance->proxyFactory(); - if(proxyFactory) - { - proxyFactory->checkRetryAfterException(ex, cnt); - } - else - { - ex.ice_throw(); // The communicator is already destroyed, so we cannot retry. - } -*/ - - try - { - ice_exception(exc); - } - catch(const Exception& ex) - { - warning(ex); - } - catch(const std::exception& ex) - { - warning(ex); - } - catch(...) - { - warning(); - } + assert(_reference); + _reference = 0; assert(_connection); _connection->decProxyCount(); @@ -216,69 +280,6 @@ IceInternal::OutgoingAsync::__finished(const LocalException& exc) __os = 0; } -bool -IceInternal::OutgoingAsync::__timedOut() const -{ - if(_connection->timeout() >= 0) - { - return IceUtil::Time::now() >= _absoluteTimeout; - } - else - { - return false; - } -} - -void -IceInternal::OutgoingAsync::__prepare(const string& operation, OperationMode mode, const Context& context) -{ - assert(!_connection); - _connection = _reference->getConnection(); - _connection->incProxyCount(); - - assert(!__is); - __is = new BasicStream(_reference->instance.get()); - - assert(!__os); - __os = new BasicStream(_reference->instance.get()); - - _connection->prepareRequest(__os); - _reference->identity.__write(__os); - __os->write(_reference->facet); - __os->write(operation); - __os->write(static_cast<Byte>(mode)); - __os->writeSize(Int(context.size())); - Context::const_iterator p; - for(p = context.begin(); p != context.end(); ++p) - { - __os->write(p->first); - __os->write(p->second); - } - - __os->startWriteEncaps(); -} - -void -IceInternal::OutgoingAsync::__send() -{ - if(_connection->timeout() >= 0) - { - _absoluteTimeout = IceUtil::Time::now() + IceUtil::Time::milliSeconds(_connection->timeout()); - } - - try - { - _connection->sendAsyncRequest(__os, this); - } - catch(const LocalException&) - { - // - // Twoway requests report exceptions using finished(). - // - assert(false); - } -} - void IceInternal::OutgoingAsync::warning(const Exception& ex) const { @@ -310,12 +311,12 @@ IceInternal::OutgoingAsync::warning() const } void -Ice::AMI_Object_ice_invoke::__invoke(const string& operation, OperationMode mode, const vector<Byte>& inParams, - const Context& context) +Ice::AMI_Object_ice_invoke::__invoke(const IceInternal::ReferencePtr& ref, const string& operation, OperationMode mode, + const vector<Byte>& inParams, const Context& context) { try { - __prepare(operation, mode, context); + __prepare(ref, operation, mode, context); __os->writeBlob(inParams); __os->endWriteEncaps(); } diff --git a/cpp/src/Ice/Proxy.cpp b/cpp/src/Ice/Proxy.cpp index 504ab0502f6..97673174e75 100644 --- a/cpp/src/Ice/Proxy.cpp +++ b/cpp/src/Ice/Proxy.cpp @@ -322,8 +322,7 @@ IceProxy::Ice::Object::ice_invoke_async(const AMI_Object_ice_invokePtr& cb, const Context& context) { __checkTwowayOnly("ice_invoke_async"); - cb->__setup(__reference()); - cb->__invoke(operation, mode, inParams, context); + cb->__invoke(__reference(), operation, mode, inParams, context); } diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 381ec7f2b4e..acb44b529af 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -1245,8 +1245,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) C << sb; // Async requests may only be sent twoway. C << nl << "__checkTwowayOnly(\"" << p->name() << "\");"; - C << nl << "__cb->__setup(__reference());"; - C << nl << "__cb->__invoke" << spar << argsAMI << "__ctx" << epar << ';'; + C << nl << "__cb->__invoke" << spar << "__reference()" << argsAMI << "__ctx" << epar << ';'; C << eb; } } @@ -3342,6 +3341,10 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) vector<string> paramsDeclInvoke; vector<string> argsInvoke; + paramsInvoke.push_back("const ::IceInternal::ReferencePtr&"); + paramsDeclInvoke.push_back("const ::IceInternal::ReferencePtr& __ref"); + argsInvoke.push_back("__ref"); + TypePtr ret = p->returnType(); string retS = inputTypeToString(ret); @@ -3412,7 +3415,7 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) C << nl << "try"; C << sb; C << nl << "static const ::std::string __operation(\"" << p->name() << "\");"; - C << nl << "__prepare(__operation, " << "static_cast< ::Ice::OperationMode>(" << p->mode() << "), __ctx);"; + C << nl << "__prepare(__ref, __operation, static_cast< ::Ice::OperationMode>(" << p->mode() << "), __ctx);"; writeMarshalCode(C, inParams, 0); if(p->sendsClasses()) { |