diff options
author | Benoit Foucher <benoit@zeroc.com> | 2007-05-04 09:29:36 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2007-05-04 09:29:36 +0000 |
commit | 370561355363d554a57fddae057dd7365fe055ac (patch) | |
tree | 183acc5269fe916e6459fd03310c5d53e21c6224 /cppe/src | |
parent | Bug 1022. (diff) | |
download | ice-370561355363d554a57fddae057dd7365fe055ac.tar.bz2 ice-370561355363d554a57fddae057dd7365fe055ac.tar.xz ice-370561355363d554a57fddae057dd7365fe055ac.zip |
Fixed bug 2177
Diffstat (limited to 'cppe/src')
-rwxr-xr-x | cppe/src/IceE/Connection.cpp | 10 | ||||
-rw-r--r-- | cppe/src/IceE/Endpoint.h | 10 | ||||
-rw-r--r-- | cppe/src/IceE/Instance.cpp | 4 | ||||
-rwxr-xr-x | cppe/src/IceE/LocalException.cpp | 10 | ||||
-rw-r--r-- | cppe/src/IceE/ObjectAdapter.cpp | 10 | ||||
-rw-r--r-- | cppe/src/IceE/Outgoing.cpp | 26 | ||||
-rw-r--r-- | cppe/src/IceE/Proxy.cpp | 81 | ||||
-rw-r--r-- | cppe/src/IceE/Reference.cpp | 284 | ||||
-rw-r--r-- | cppe/src/IceE/Reference.h | 43 | ||||
-rw-r--r-- | cppe/src/IceE/ReferenceFactory.cpp | 120 | ||||
-rw-r--r-- | cppe/src/IceE/ReferenceFactory.h | 8 | ||||
-rw-r--r-- | cppe/src/IceE/UnknownEndpoint.cpp | 12 | ||||
-rw-r--r-- | cppe/src/IceE/UnknownEndpoint.h | 2 | ||||
-rw-r--r-- | cppe/src/TcpTransport/EndpointFactory.cpp | 4 | ||||
-rw-r--r-- | cppe/src/TcpTransport/TcpEndpoint.cpp | 12 | ||||
-rw-r--r-- | cppe/src/TcpTransport/TcpEndpoint.h | 2 |
16 files changed, 362 insertions, 276 deletions
diff --git a/cppe/src/IceE/Connection.cpp b/cppe/src/IceE/Connection.cpp index 8972e0f52c2..ede6a022e86 100755 --- a/cppe/src/IceE/Connection.cpp +++ b/cppe/src/IceE/Connection.cpp @@ -906,9 +906,7 @@ Ice::Connection::setAdapter(const ObjectAdapterPtr& adapter) if(_blocking) { - FeatureNotSupportedException ex(__FILE__, __LINE__); - ex.unsupportedFeature = "setAdapter with blocking connection"; - throw ex; + throw FeatureNotSupportedException(__FILE__, __LINE__, "setAdapter with blocking connection"); } // @@ -947,7 +945,7 @@ Ice::Connection::createProxy(const Identity& ident) const // vector<ConnectionPtr> connections; connections.push_back(const_cast<Connection*>(this)); - ReferencePtr ref = _instance->referenceFactory()->create(ident, Ice::Context(), "", Reference::ModeTwoway, + ReferencePtr ref = _instance->referenceFactory()->create(ident, Ice::Context(), "", ReferenceModeTwoway, connections); return _instance->proxyFactory()->referenceToProxy(ref); } @@ -1518,9 +1516,7 @@ Ice::Connection::readStreamAndParseMessage(IceInternal::BasicStream& stream, Int const Byte messageType = header[8]; if(header[9] == 2) { - FeatureNotSupportedException ex(__FILE__, __LINE__); - ex.unsupportedFeature = "compression"; - throw ex; + throw FeatureNotSupportedException(__FILE__, __LINE__, "compression"); } Int size; diff --git a/cppe/src/IceE/Endpoint.h b/cppe/src/IceE/Endpoint.h index 29a01407c1d..1026c1d0cd4 100644 --- a/cppe/src/IceE/Endpoint.h +++ b/cppe/src/IceE/Endpoint.h @@ -59,6 +59,16 @@ public: virtual EndpointPtr timeout(Ice::Int) const = 0; // + // Return true if the endpoint is datagram-based. + // + virtual bool datagram() const = 0; + + // + // Return true if the endpoint is secure. + // + virtual bool secure() const = 0; + + // // Return true if the endpoint type is unknown. // virtual bool unknown() const = 0; diff --git a/cppe/src/IceE/Instance.cpp b/cppe/src/IceE/Instance.cpp index 8906459ab64..6c6b29a5c88 100644 --- a/cppe/src/IceE/Instance.cpp +++ b/cppe/src/IceE/Instance.cpp @@ -624,7 +624,7 @@ IceInternal::Instance::finishSetup(int& argc, char* argv[]) #endif } -void
+void IceInternal::Instance::destroy() { { @@ -717,7 +717,7 @@ IceInternal::Instance::destroy() } _state = StateDestroyed; - }
+ } } #ifdef ICEE_HAS_WSTRING diff --git a/cppe/src/IceE/LocalException.cpp b/cppe/src/IceE/LocalException.cpp index ed1b190c353..2eff703326f 100755 --- a/cppe/src/IceE/LocalException.cpp +++ b/cppe/src/IceE/LocalException.cpp @@ -1526,6 +1526,16 @@ Ice::FeatureNotSupportedException::FeatureNotSupportedException(const char* __fi { } +Ice::FeatureNotSupportedException::FeatureNotSupportedException(const char* __file, int __line, const string& __unsupportedFeature) : +#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug + LocalException(__file, __line), +#else + ::Ice::LocalException(__file, __line), +#endif + unsupportedFeature(__unsupportedFeature) +{ +} + Ice::FeatureNotSupportedException::~FeatureNotSupportedException() throw() { } diff --git a/cppe/src/IceE/ObjectAdapter.cpp b/cppe/src/IceE/ObjectAdapter.cpp index cc44d174014..11856d3519c 100644 --- a/cppe/src/IceE/ObjectAdapter.cpp +++ b/cppe/src/IceE/ObjectAdapter.cpp @@ -532,7 +532,7 @@ Ice::ObjectAdapter::createReverseProxy(const Identity& ident) const // reference. // vector<EndpointPtr> endpoints; - ReferencePtr ref = _instance->referenceFactory()->create(ident, Ice::Context(), "", Reference::ModeTwoway, + ReferencePtr ref = _instance->referenceFactory()->create(ident, Ice::Context(), "", ReferenceModeTwoway, connections); return _instance->proxyFactory()->referenceToProxy(ref); } @@ -796,10 +796,10 @@ Ice::ObjectAdapter::newDirectProxy(const Identity& ident, const string& facet) c // Create a reference and return a proxy for this reference. // #ifdef ICEE_HAS_ROUTER - ReferencePtr ref = _instance->referenceFactory()->create(ident, Ice::Context(), facet, Reference::ModeTwoway, + ReferencePtr ref = _instance->referenceFactory()->create(ident, Ice::Context(), facet, ReferenceModeTwoway, false, endpoints, 0); #else - ReferencePtr ref = _instance->referenceFactory()->create(ident, Ice::Context(), facet, Reference::ModeTwoway, + ReferencePtr ref = _instance->referenceFactory()->create(ident, Ice::Context(), facet, ReferenceModeTwoway, false, endpoints); #endif return _instance->proxyFactory()->referenceToProxy(ref); @@ -815,11 +815,11 @@ Ice::ObjectAdapter::newIndirectProxy(const Identity& ident, const string& facet, // #ifdef ICEE_HAS_ROUTER ReferencePtr ref = - _instance->referenceFactory()->create(ident, Ice::Context(), facet, Reference::ModeTwoway, false, id, 0, + _instance->referenceFactory()->create(ident, Ice::Context(), facet, ReferenceModeTwoway, false, id, 0, _locatorInfo); #else ReferencePtr ref = - _instance->referenceFactory()->create(ident, Ice::Context(), facet, Reference::ModeTwoway, false, id, + _instance->referenceFactory()->create(ident, Ice::Context(), facet, ReferenceModeTwoway, false, id, _locatorInfo); #endif diff --git a/cppe/src/IceE/Outgoing.cpp b/cppe/src/IceE/Outgoing.cpp index d2573a78784..b428342ae3b 100644 --- a/cppe/src/IceE/Outgoing.cpp +++ b/cppe/src/IceE/Outgoing.cpp @@ -58,22 +58,22 @@ IceInternal::Outgoing::Outgoing(Connection* connection, Reference* ref, const st { switch(_reference->getMode()) { - case Reference::ModeTwoway: - case Reference::ModeOneway: + case ReferenceModeTwoway: + case ReferenceModeOneway: { _stream.writeBlob(requestHdr, sizeof(requestHdr)); break; } - case Reference::ModeBatchOneway: + case ReferenceModeBatchOneway: #ifdef ICEE_HAS_BATCH { _connection->prepareBatchRequest(&_stream); break; } #endif - case Reference::ModeDatagram: - case Reference::ModeBatchDatagram: + case ReferenceModeDatagram: + case ReferenceModeBatchDatagram: { assert(false); break; @@ -134,7 +134,7 @@ IceInternal::Outgoing::invoke() switch(_reference->getMode()) { - case Reference::ModeTwoway: + case ReferenceModeTwoway: { // // We let all exceptions raised by sending directly @@ -182,7 +182,7 @@ IceInternal::Outgoing::invoke() break; } - case Reference::ModeOneway: + case ReferenceModeOneway: { // // For oneway requests, the connection object @@ -196,7 +196,7 @@ IceInternal::Outgoing::invoke() break; } - case Reference::ModeBatchOneway: + case ReferenceModeBatchOneway: #ifdef ICEE_HAS_BATCH { // @@ -208,8 +208,8 @@ IceInternal::Outgoing::invoke() break; } #endif - case Reference::ModeDatagram: - case Reference::ModeBatchDatagram: + case ReferenceModeDatagram: + case ReferenceModeBatchDatagram: { assert(false); return false; @@ -230,7 +230,7 @@ IceInternal::Outgoing::abort(const LocalException& ex) // batch stream. // #ifdef ICEE_HAS_BATCH - if(_reference->getMode() == Reference::ModeBatchOneway) + if(_reference->getMode() == ReferenceModeBatchOneway) { _connection->abortBatchRequest(); @@ -249,7 +249,7 @@ IceInternal::Outgoing::abort(const LocalException& ex) void IceInternal::Outgoing::finished(BasicStream& is) { - assert(_reference->getMode() == Reference::ModeTwoway); // Can only be called for twoways. + assert(_reference->getMode() == ReferenceModeTwoway); // Can only be called for twoways. assert(_state <= StateInProgress); // @@ -418,7 +418,7 @@ IceInternal::Outgoing::finished(BasicStream& is) void IceInternal::Outgoing::finished(const LocalException& ex) { - assert(_reference->getMode() == Reference::ModeTwoway); // Can only be called for twoways. + assert(_reference->getMode() == ReferenceModeTwoway); // Can only be called for twoways. assert(_state <= StateInProgress); _state = StateLocalException; diff --git a/cppe/src/IceE/Proxy.cpp b/cppe/src/IceE/Proxy.cpp index f8704226b24..f9f9f4e1cd4 100644 --- a/cppe/src/IceE/Proxy.cpp +++ b/cppe/src/IceE/Proxy.cpp @@ -534,71 +534,27 @@ IceProxy::Ice::Object::ice_locator(const LocatorPrx& locator) const #endif -ObjectPrx -IceProxy::Ice::Object::ice_twoway() const -{ - if(_reference->getMode() == Reference::ModeTwoway) - { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); - } - else - { - ObjectPrx proxy(new ::IceProxy::Ice::Object()); - proxy->setup(_reference->changeMode(Reference::ModeTwoway)); - return proxy; - } -} - bool -IceProxy::Ice::Object::ice_isTwoway() const +IceProxy::Ice::Object::ice_isSecure() const { - return _reference->getMode() == Reference::ModeTwoway; + return _reference->getSecure(); } ObjectPrx -IceProxy::Ice::Object::ice_oneway() const +IceProxy::Ice::Object::ice_secure(bool b) const { - if(_reference->getMode() == Reference::ModeOneway) + if(b == _reference->getSecure()) { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); } else { - ObjectPrx proxy(new ::IceProxy::Ice::Object()); - proxy->setup(_reference->changeMode(Reference::ModeOneway)); - return proxy; + ObjectPrx proxy(new ::IceProxy::Ice::Object()); + proxy->setup(_reference->changeSecure(b)); + return proxy; } } -bool -IceProxy::Ice::Object::ice_isOneway() const -{ - return _reference->getMode() == Reference::ModeOneway; -} - -#ifdef ICEE_HAS_BATCH -ObjectPrx -IceProxy::Ice::Object::ice_batchOneway() const -{ - if(_reference->getMode() == Reference::ModeBatchOneway) - { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); - } - else - { - ObjectPrx proxy(new ::IceProxy::Ice::Object()); - proxy->setup(_reference->changeMode(Reference::ModeBatchOneway)); - return proxy; - } -} - -bool -IceProxy::Ice::Object::ice_isBatchOneway() const -{ - return _reference->getMode() == Reference::ModeBatchOneway; -} -#endif - ObjectPrx IceProxy::Ice::Object::ice_timeout(int t) const { @@ -752,6 +708,27 @@ IceProxy::Ice::Object::__checkTwowayOnly(const char* name) const } } +ReferenceMode +IceProxy::Ice::Object::getMode() const +{ + return _reference->getMode(); +} + +ObjectPrx +IceProxy::Ice::Object::changeMode(ReferenceMode newMode) const +{ + if(_reference->getMode() == newMode) + { + return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + } + else + { + ObjectPrx proxy(new ::IceProxy::Ice::Object()); + proxy->setup(_reference->changeMode(newMode)); + return proxy; + } +} + bool Ice::proxyIdentityLess(const ObjectPrx& lhs, const ObjectPrx& rhs) { diff --git a/cppe/src/IceE/Reference.cpp b/cppe/src/IceE/Reference.cpp index 0b5a3e71dd4..16319eab04a 100644 --- a/cppe/src/IceE/Reference.cpp +++ b/cppe/src/IceE/Reference.cpp @@ -37,6 +37,28 @@ using namespace IceInternal; IceUtil::Shared* IceInternal::upCast(IceInternal::Reference* p) { return p; } +class ConnectionIsDatagram : public unary_function<ConnectionPtr, bool> +{ +public: + + bool + operator()(ConnectionPtr p) const + { + return p->endpoint()->datagram(); + } +}; + +class ConnectionIsSecure : public unary_function<ConnectionPtr, bool> +{ +public: + + bool + operator()(ConnectionPtr p) const + { + return p->endpoint()->secure(); + } +}; + CommunicatorPtr IceInternal::Reference::getCommunicator() const { @@ -52,7 +74,7 @@ IceInternal::Reference::changeContext(const Context& newContext) const } ReferencePtr -IceInternal::Reference::changeMode(Mode newMode) const +IceInternal::Reference::changeMode(ReferenceMode newMode) const { if(newMode == _mode) { @@ -64,6 +86,18 @@ IceInternal::Reference::changeMode(Mode newMode) const } ReferencePtr +IceInternal::Reference::changeSecure(bool newSecure) const +{ + if(newSecure == _secure) + { + return ReferencePtr(const_cast<Reference*>(this)); + } + ReferencePtr r = _instance->referenceFactory()->copy(this); + r->_secure = newSecure; + return r; +} + +ReferencePtr IceInternal::Reference::changeIdentity(const Identity& newIdentity) const { if(newIdentity == _identity) @@ -233,31 +267,31 @@ IceInternal::Reference::toString() const switch(_mode) { - case ModeTwoway: + case ReferenceModeTwoway: { s += " -t"; break; } - case ModeOneway: + case ReferenceModeOneway: { s += " -o"; break; } - case ModeBatchOneway: + case ReferenceModeBatchOneway: { s += " -O"; break; } - case ModeDatagram: + case ReferenceModeDatagram: { s += " -d"; break; } - case ModeBatchDatagram: + case ReferenceModeBatchDatagram: { s += " -D"; break; @@ -404,7 +438,7 @@ IceInternal::Reference::operator<(const Reference& r) const } IceInternal::Reference::Reference(const InstancePtr& inst, const CommunicatorPtr& com, const Identity& ident, - const Context& context, const string& fs, Mode md, bool sec) : + const Context& context, const string& fs, ReferenceMode md, bool sec) : _hashInitialized(false), _instance(inst), _communicator(com), @@ -450,7 +484,7 @@ IceInternal::Reference::applyOverrides(vector<EndpointPtr>& endpts) const IceUtil::Shared* IceInternal::upCast(IceInternal::FixedReference* p) { return p; } IceInternal::FixedReference::FixedReference(const InstancePtr& inst, const CommunicatorPtr& com, const Identity& ident, - const Context& context, const string& fs, Mode md, + const Context& context, const string& fs, ReferenceMode md, const vector<ConnectionPtr>& fixedConns) : Reference(inst, com, ident, context, fs, md, false), _fixedConnections(fixedConns) @@ -527,52 +561,89 @@ IceInternal::FixedReference::toString() const ConnectionPtr IceInternal::FixedReference::getConnection() const { + vector<ConnectionPtr> connections = _fixedConnections; + switch(getMode()) + { + case ReferenceModeTwoway: + case ReferenceModeOneway: +#ifdef ICEE_HAS_BATCH + case ReferenceModeBatchOneway: +#endif + { + // + // Filter out datagram connections. + // + connections.erase(remove_if(connections.begin(), connections.end(), ConnectionIsDatagram()), + connections.end()); + break; + } + + case ReferenceModeDatagram: +#ifdef ICEE_HAS_BATCH + case ReferenceModeBatchDatagram: +#endif + { + // + // Filter out non-datagram connections. + // + connections.erase(remove_if(connections.begin(), connections.end(), not1(ConnectionIsDatagram())), + connections.end()); + break; + } + +#ifndef ICEE_HAS_BATCH + case ReferenceModeBatchDatagram: + case ReferenceModeBatchOneway: + { + throw FeatureNotSupportedException(__FILE__, __LINE__, "batch proxy mode"); + } +#endif + } + // // Randomize the order of connections. // - // If a reference is secure or the mode is datagram or batch - // datagram then we throw a NoEndpointException since IceE lacks - // this support. + random_shuffle(connections.begin(), connections.end()); + // - if(getSecure() || getMode() == ModeDatagram || getMode() == ModeBatchDatagram || _fixedConnections.empty() -#ifndef ICEE_HAS_BATCH - || getMode() == ModeBatchOneway -#endif - ) + // If a secure connection is requested or secure overrides is set, + // remove all non-secure connections. Otherwise make non-secure + // connections preferred over secure connections by partitioning + // the connection vector, so that non-secure connections come + // first. + // + // NOTE: we don't use the stable_partition algorithm from STL to + // keep the code size down. + // + vector<ConnectionPtr>::iterator p = connections.begin(); + vector<ConnectionPtr> secureConnections; + while(p != connections.end()) { - if(_fixedConnections.empty()) + if((*p)->endpoint()->secure()) { - NoEndpointException ex(__FILE__, __LINE__); - ex.proxy = ""; // No stringified representation for fixed proxies. - throw ex; + secureConnections.push_back(*p); + p = connections.erase(p); } - - FeatureNotSupportedException ex(__FILE__, __LINE__); - if(getSecure()) - { - ex.unsupportedFeature = "ssl"; - } - else if(getMode() == ModeDatagram) - { - ex.unsupportedFeature = "datagram"; - } - else if(getMode() == ModeBatchDatagram) - { - ex.unsupportedFeature = "batch datagram"; - } -#ifndef ICEE_HAS_BATCH - else if(getMode() == ModeBatchOneway) + else { - ex.unsupportedFeature = "batch"; + ++p; } -#endif - throw ex; + } + if(getSecure()) + { + connections.swap(secureConnections); + } + else + { + connections.insert(connections.end(), secureConnections.begin(), secureConnections.end()); + } + + if(connections.empty()) + { + throw NoEndpointException(__FILE__, __LINE__); // No stringified representation for fixed proxies. } - vector<ConnectionPtr> randomCons = _fixedConnections; - random_shuffle(randomCons.begin(), randomCons.end()); - - ConnectionPtr connection = randomCons[0]; + ConnectionPtr connection = connections[0]; assert(connection); connection->throwException(); // Throw in case our connection is already destroyed. @@ -699,7 +770,7 @@ IceInternal::RoutableReference::operator<(const Reference& r) const IceInternal::RoutableReference::RoutableReference(const InstancePtr& inst, const CommunicatorPtr& com, const Identity& ident, const Context& context, const string& fs, - Mode md, bool sec, const RouterInfoPtr& rtrInfo) : + ReferenceMode md, bool sec, const RouterInfoPtr& rtrInfo) : Reference(inst, com, ident, context, fs, md, sec), _routerInfo(rtrInfo) { } @@ -715,7 +786,7 @@ IceUtil::Shared* IceInternal::upCast(IceInternal::DirectReference* p) { return p #ifdef ICEE_HAS_ROUTER IceInternal::DirectReference::DirectReference(const InstancePtr& inst, const CommunicatorPtr& com, - const Identity& ident, const Context& context, const string& fs, Mode md, + const Identity& ident, const Context& context, const string& fs, ReferenceMode md, bool sec, const vector<EndpointPtr>& endpts, const RouterInfoPtr& rtrInfo) : @@ -725,7 +796,7 @@ IceInternal::DirectReference::DirectReference(const InstancePtr& inst, const Com } #else IceInternal::DirectReference::DirectReference(const InstancePtr& inst, const CommunicatorPtr& com, - const Identity& ident, const Context& context, const string& fs, Mode md, + const Identity& ident, const Context& context, const string& fs, ReferenceMode md, bool sec, const vector<EndpointPtr>& endpts) : Reference(inst, com, ident, context, fs, md, sec), _endpoints(endpts) @@ -852,9 +923,7 @@ IceInternal::DirectReference::getConnection() const vector<EndpointPtr> filteredEndpoints = filterEndpoints(endpts, getMode(), getSecure()); if(filteredEndpoints.empty()) { - NoEndpointException ex(__FILE__, __LINE__); - ex.proxy = toString(); - throw ex; + throw NoEndpointException(__FILE__, __LINE__, toString()); } OutgoingConnectionFactoryPtr factory = getInstance()->outgoingConnectionFactory(); @@ -930,7 +999,7 @@ IceUtil::Shared* IceInternal::upCast(IceInternal::IndirectReference* p) { return #ifdef ICEE_HAS_ROUTER IceInternal::IndirectReference::IndirectReference(const InstancePtr& inst, const CommunicatorPtr& com, const Identity& ident, const Context& context, const string& fs, - Mode md, bool sec, const string& adptid, + ReferenceMode md, bool sec, const string& adptid, const RouterInfoPtr& rtrInfo, const LocatorInfoPtr& locInfo) : RoutableReference(inst, com, ident, context, fs, md, sec, rtrInfo), _adapterId(adptid), @@ -940,7 +1009,7 @@ IceInternal::IndirectReference::IndirectReference(const InstancePtr& inst, const #else IceInternal::IndirectReference::IndirectReference(const InstancePtr& inst, const CommunicatorPtr& com, const Identity& ident, const Context& context, const string& fs, - Mode md, bool sec, const string& adptid, + ReferenceMode md, bool sec, const string& adptid, const LocatorInfoPtr& locInfo) : Reference(inst, com, ident, context, fs, md, sec), _adapterId(adptid), @@ -1064,9 +1133,7 @@ IceInternal::IndirectReference::getConnection() const vector<EndpointPtr> filteredEndpoints = filterEndpoints(endpts, getMode(), getSecure()); if(filteredEndpoints.empty()) { - NoEndpointException ex(__FILE__, __LINE__); - ex.proxy = toString(); - throw ex; + throw NoEndpointException(__FILE__, __LINE__, toString()); } try @@ -1201,56 +1268,95 @@ IceInternal::IndirectReference::IndirectReference(const IndirectReference& r) #endif // ICEE_HAS_LOCATOR vector<EndpointPtr> -IceInternal::filterEndpoints(const vector<EndpointPtr>& allEndpoints, Reference::Mode m, bool sec) +IceInternal::filterEndpoints(const vector<EndpointPtr>& allEndpoints, ReferenceMode m, bool sec) { - vector<EndpointPtr> endpoints; + vector<EndpointPtr> endpoints = allEndpoints; // - // If a secure endpoint, batch (if batch is not supported), - // datagram or batch datagram endpoint is requested since IceE - // lacks this support we throw an unsupported feature. + // Filter out unknown endpoints. // - if(sec || m == Reference::ModeDatagram || m == Reference::ModeBatchDatagram -#ifndef ICEE_HAS_BATCH - || m == Reference::ModeBatchOneway -#endif - ) + endpoints.erase(remove_if(endpoints.begin(), endpoints.end(), Ice::constMemFun(&Endpoint::unknown)), + endpoints.end()); + + // + // Filter out endpoints according to the mode of the reference. + // + switch(m) { - FeatureNotSupportedException ex(__FILE__, __LINE__); - if(sec) - { - ex.unsupportedFeature = "ssl"; - } - else if(m == Reference::ModeDatagram) - { - ex.unsupportedFeature = "datagram"; - } - else if(m == Reference::ModeBatchDatagram) - { - ex.unsupportedFeature = "batch datagram"; - } + case ReferenceModeTwoway: + case ReferenceModeOneway: +#ifdef ICEE_HAS_BATCH + case ReferenceModeBatchOneway: +#endif + { + // + // Filter out datagram endpoints. + // + endpoints.erase(remove_if(endpoints.begin(), endpoints.end(), Ice::constMemFun(&Endpoint::datagram)), + endpoints.end()); + break; + } + + case ReferenceModeDatagram: +#ifdef ICEE_HAS_BATCH + case ReferenceModeBatchDatagram: +#endif + { + // + // Filter out non-datagram endpoints. + // + endpoints.erase(remove_if(endpoints.begin(), endpoints.end(), + not1(Ice::constMemFun(&Endpoint::datagram))), + endpoints.end()); + break; + } + #ifndef ICEE_HAS_BATCH - else if(m == Reference::ModeBatchOneway) + case ReferenceModeBatchDatagram: + case ReferenceModeBatchOneway: { - ex.unsupportedFeature = "batch"; + throw FeatureNotSupportedException(__FILE__, __LINE__, "batch proxy mode"); } #endif - ex.unsupportedFeature += " proxy mode"; - throw ex; } - endpoints = allEndpoints; - - // - // Filter out unknown endpoints. - // - endpoints.erase(remove_if(endpoints.begin(), endpoints.end(), Ice::constMemFun(&Endpoint::unknown)), - endpoints.end()); - // // Randomize the order of endpoints. // random_shuffle(endpoints.begin(), endpoints.end()); + // + // If a secure connection is requested or secure overrides is set, + // remove all non-secure endpoints. Otherwise make non-secure + // endpoints preferred over secure endpoints by partitioning + // the endpoint vector, so that non-secure endpoints come + // first. + // + // NOTE: we don't use the stable_partition algorithm from STL to + // keep the code size down. + // + vector<EndpointPtr>::iterator p = endpoints.begin(); + vector<EndpointPtr> secureEndpoints; + while(p != endpoints.end()) + { + if((*p)->secure()) + { + secureEndpoints.push_back(*p); + p = endpoints.erase(p); + } + else + { + ++p; + } + } + if(sec) + { + endpoints.swap(secureEndpoints); + } + else + { + endpoints.insert(endpoints.end(), secureEndpoints.begin(), secureEndpoints.end()); + } + return endpoints; } diff --git a/cppe/src/IceE/Reference.h b/cppe/src/IceE/Reference.h index bac2d588107..d8297d832a2 100644 --- a/cppe/src/IceE/Reference.h +++ b/cppe/src/IceE/Reference.h @@ -43,17 +43,21 @@ public: TypeFixed }; - enum Mode - { - ModeTwoway, - ModeOneway, - ModeBatchOneway, - ModeDatagram, - ModeBatchDatagram, - ModeLast = ModeBatchDatagram - }; - - Mode getMode() const { return _mode; } + // + // The reference mode in Ice-E is defined in ReferenceF.h to allow the proxy + // to inline methods such as ice_twoway, ice_isTwoway, etc. + // +// enum Mode +// { +// ModeTwoway, +// ModeOneway, +// ModeBatchOneway, +// ModeDatagram, +// ModeBatchDatagram, +// ModeLast = ModeBatchDatagram +// }; + + ReferenceMode getMode() const { return _mode; } bool getSecure() const { return _secure; }; const Ice::Identity& getIdentity() const { return _identity; } const std::string& getFacet() const { return _facet; } @@ -79,7 +83,8 @@ public: // corresponding value changed. // ReferencePtr changeContext(const Ice::Context&) const; - ReferencePtr changeMode(Mode) const; + ReferencePtr changeMode(ReferenceMode) const; + ReferencePtr changeSecure(bool) const; ReferencePtr changeIdentity(const Ice::Identity&) const; ReferencePtr changeFacet(const std::string&) const; @@ -117,7 +122,7 @@ public: protected: Reference(const InstancePtr&, const Ice::CommunicatorPtr&, const Ice::Identity&, const Ice::Context&, - const std::string&, Mode, bool); + const std::string&, ReferenceMode, bool); Reference(const Reference&); void applyOverrides(std::vector<EndpointPtr>&) const; @@ -131,7 +136,7 @@ private: const InstancePtr _instance; const Ice::CommunicatorPtr _communicator; - Mode _mode; + ReferenceMode _mode; bool _secure; Ice::Identity _identity; Ice::Context _context; @@ -153,7 +158,7 @@ class FixedReference : public Reference public: FixedReference(const InstancePtr&, const Ice::CommunicatorPtr&, const Ice::Identity&, const Ice::Context&, - const std::string&, Mode, const std::vector<Ice::ConnectionPtr>&); + const std::string&, ReferenceMode, const std::vector<Ice::ConnectionPtr>&); virtual Type getType() const; virtual std::vector<EndpointPtr> getEndpoints() const; @@ -209,7 +214,7 @@ public: protected: RoutableReference(const InstancePtr&, const Ice::CommunicatorPtr&, const Ice::Identity&, const Ice::Context&, - const std::string&, Mode, bool, const RouterInfoPtr&); + const std::string&, ReferenceMode, bool, const RouterInfoPtr&); RoutableReference(const RoutableReference&); @@ -229,7 +234,7 @@ class DirectReference : public: DirectReference(const InstancePtr&, const Ice::CommunicatorPtr&, const Ice::Identity&, const Ice::Context&, - const std::string&, Mode, bool, const std::vector<EndpointPtr>& + const std::string&, ReferenceMode, bool, const std::vector<EndpointPtr>& #ifdef ICEE_HAS_ROUTER , const RouterInfoPtr& #endif @@ -281,7 +286,7 @@ class IndirectReference : public: IndirectReference(const InstancePtr&, const Ice::CommunicatorPtr&, const Ice::Identity&, const Ice::Context&, - const std::string&, Mode, bool, const std::string& + const std::string&, ReferenceMode, bool, const std::string& #ifdef ICEE_HAS_ROUTER , const RouterInfoPtr& #endif @@ -324,7 +329,7 @@ private: #endif // ICEE_HAS_LOCATOR -std::vector<EndpointPtr> filterEndpoints(const std::vector<EndpointPtr>&, Reference::Mode, bool); +std::vector<EndpointPtr> filterEndpoints(const std::vector<EndpointPtr>&, ReferenceMode, bool); } diff --git a/cppe/src/IceE/ReferenceFactory.cpp b/cppe/src/IceE/ReferenceFactory.cpp index df4aba6f999..571b9628834 100644 --- a/cppe/src/IceE/ReferenceFactory.cpp +++ b/cppe/src/IceE/ReferenceFactory.cpp @@ -55,7 +55,7 @@ ReferencePtr IceInternal::ReferenceFactory::create(const Identity& ident, const Context& context, const string& facet, - Reference::Mode mode, + ReferenceMode mode, bool secure, const vector<EndpointPtr>& endpoints #ifdef ICEE_HAS_ROUTER @@ -91,7 +91,7 @@ ReferencePtr IceInternal::ReferenceFactory::create(const Identity& ident, const Context& context, const string& facet, - Reference::Mode mode, + ReferenceMode mode, bool secure, const string& adapterId #ifdef ICEE_HAS_ROUTER @@ -128,7 +128,7 @@ ReferencePtr IceInternal::ReferenceFactory::create(const Identity& ident, const Context& context, const string& facet, - Reference::Mode mode, + ReferenceMode mode, const vector<Ice::ConnectionPtr>& fixedConnections) { Mutex::Lock sync(*this); @@ -166,9 +166,7 @@ IceInternal::ReferenceFactory::create(const string& str) beg = s.find_first_not_of(delim, end); if(beg == string::npos) { - ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; - throw ex; + throw ProxyParseException(__FILE__, __LINE__, str); } // @@ -179,9 +177,7 @@ IceInternal::ReferenceFactory::create(const string& str) end = IceUtil::checkQuote(s, beg); if(end == string::npos) { - ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; - throw ex; + throw ProxyParseException(__FILE__, __LINE__, str); } else if(end == 0) { @@ -201,9 +197,7 @@ IceInternal::ReferenceFactory::create(const string& str) if(beg == end) { - ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; - throw ex; + throw ProxyParseException(__FILE__, __LINE__, str); } // @@ -219,9 +213,7 @@ IceInternal::ReferenceFactory::create(const string& str) // if(!ident.category.empty()) { - IllegalIdentityException e(__FILE__, __LINE__); - e.id = ident; - throw e; + throw IllegalIdentityException(__FILE__, __LINE__, ident); } // // Treat a stringified proxy containing two double @@ -231,9 +223,7 @@ IceInternal::ReferenceFactory::create(const string& str) // else if(s.find_first_not_of(delim, end) != string::npos) { - ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; - throw ex; + throw ProxyParseException(__FILE__, __LINE__, str); } else { @@ -242,7 +232,7 @@ IceInternal::ReferenceFactory::create(const string& str) } string facet; - Reference::Mode mode = Reference::ModeTwoway; + ReferenceMode mode = ReferenceModeTwoway; bool secure = false; string adapter; @@ -273,9 +263,7 @@ IceInternal::ReferenceFactory::create(const string& str) string option = s.substr(beg, end - beg); if(option.length() != 2 || option[0] != '-') { - ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; - throw ex; + throw ProxyParseException(__FILE__, __LINE__, str); } // @@ -293,9 +281,7 @@ IceInternal::ReferenceFactory::create(const string& str) end = IceUtil::checkQuote(s, beg); if(end == string::npos) { - ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; - throw ex; + throw ProxyParseException(__FILE__, __LINE__, str); } else if(end == 0) { @@ -325,16 +311,12 @@ IceInternal::ReferenceFactory::create(const string& str) { if(argument.empty()) { - ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; - throw ex; + throw ProxyParseException(__FILE__, __LINE__, str); } if(!IceUtil::unescapeString(argument, 0, argument.size(), facet)) { - ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; - throw ex; + throw ProxyParseException(__FILE__, __LINE__, str); } #ifdef ICEE_HAS_WSTRING if(_instance->initializationData().stringConverter) @@ -353,11 +335,9 @@ IceInternal::ReferenceFactory::create(const string& str) { if(!argument.empty()) { - ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; - throw ex; + throw ProxyParseException(__FILE__, __LINE__, str); } - mode = Reference::ModeTwoway; + mode = ReferenceModeTwoway; break; } @@ -365,11 +345,9 @@ IceInternal::ReferenceFactory::create(const string& str) { if(!argument.empty()) { - ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; - throw ex; + throw ProxyParseException(__FILE__, __LINE__, str); } - mode = Reference::ModeOneway; + mode = ReferenceModeOneway; break; } @@ -377,11 +355,9 @@ IceInternal::ReferenceFactory::create(const string& str) { if(!argument.empty()) { - ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; - throw ex; + throw ProxyParseException(__FILE__, __LINE__, str); } - mode = Reference::ModeBatchOneway; + mode = ReferenceModeBatchOneway; break; } @@ -389,11 +365,9 @@ IceInternal::ReferenceFactory::create(const string& str) { if(!argument.empty()) { - ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; - throw ex; + throw ProxyParseException(__FILE__, __LINE__, str); } - mode = Reference::ModeDatagram; + mode = ReferenceModeDatagram; break; } @@ -401,11 +375,9 @@ IceInternal::ReferenceFactory::create(const string& str) { if(!argument.empty()) { - ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; - throw ex; + throw ProxyParseException(__FILE__, __LINE__, str); } - mode = Reference::ModeBatchDatagram; + mode = ReferenceModeBatchDatagram; break; } @@ -413,9 +385,7 @@ IceInternal::ReferenceFactory::create(const string& str) { if(!argument.empty()) { - ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; - throw ex; + throw ProxyParseException(__FILE__, __LINE__, str); } secure = true; break; @@ -423,9 +393,7 @@ IceInternal::ReferenceFactory::create(const string& str) default: { - ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; - throw ex; + throw ProxyParseException(__FILE__, __LINE__, str); } } } @@ -446,9 +414,8 @@ IceInternal::ReferenceFactory::create(const string& str) return create(ident, Ice::Context(), facet, mode, secure, "", locatorInfo); # endif #else - FeatureNotSupportedException ex(__FILE__, __LINE__); - ex.unsupportedFeature = "indirect proxy `" + str + "' (no locator support built-in)"; - throw ex; + throw FeatureNotSupportedException(__FILE__, __LINE__, + "indirect proxy `" + str + "' (no locator support built-in)"); #endif } vector<EndpointPtr> endpoints; @@ -484,9 +451,7 @@ IceInternal::ReferenceFactory::create(const string& str) } if(endpoints.size() == 0) { - EndpointParseException ex(__FILE__, __LINE__); - ex.str = unknownEndpoints.front(); - throw ex; + throw EndpointParseException(__FILE__, __LINE__, unknownEndpoints.front()); } else if(unknownEndpoints.size() != 0 && _instance->initializationData().properties->getPropertyAsIntWithDefault( @@ -514,18 +479,14 @@ IceInternal::ReferenceFactory::create(const string& str) beg = s.find_first_not_of(delim, beg + 1); if(beg == string::npos) { - ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; - throw ex; + throw ProxyParseException(__FILE__, __LINE__, str); } string adapterstr; end = IceUtil::checkQuote(s, beg); if(end == string::npos) { - ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; - throw ex; + throw ProxyParseException(__FILE__, __LINE__, str); } else if(end == 0) { @@ -546,16 +507,12 @@ IceInternal::ReferenceFactory::create(const string& str) // Check for trailing whitespace. if(end != string::npos && s.find_first_not_of(delim, end) != string::npos) { - ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; - throw ex; + throw ProxyParseException(__FILE__, __LINE__, str); } if(!IceUtil::unescapeString(adapterstr, 0, adapterstr.size(), adapter) || adapter.size() == 0) { - ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; - throw ex; + throw ProxyParseException(__FILE__, __LINE__, str); } #ifdef ICEE_HAS_WSTRING if(_instance->initializationData().stringConverter) @@ -574,18 +531,15 @@ IceInternal::ReferenceFactory::create(const string& str) return create(ident, Ice::Context(), facet, mode, secure, adapter, locatorInfo); #endif #else - FeatureNotSupportedException ex(__FILE__, __LINE__); - ex.unsupportedFeature = "indirect proxy `" + str + "' (no locator support built-in)"; - throw ex; + throw FeatureNotSupportedException(__FILE__, __LINE__, + "indirect proxy `" + str + "' (no locator support built-in)"); #endif break; } default: { - ProxyParseException ex(__FILE__, __LINE__); - ex.str = str; - throw ex; + throw ProxyParseException(__FILE__, __LINE__, str); } } @@ -654,8 +608,8 @@ IceInternal::ReferenceFactory::create(const Identity& ident, BasicStream* s) Byte modeAsByte; s->read(modeAsByte); - Reference::Mode mode = static_cast<Reference::Mode>(modeAsByte); - if(mode < 0 || mode > Reference::ModeLast) + ReferenceMode mode = static_cast<ReferenceMode>(modeAsByte); + if(mode < 0 || mode > ReferenceModeLast) { throwProxyUnmarshalException(__FILE__, __LINE__); } diff --git a/cppe/src/IceE/ReferenceFactory.h b/cppe/src/IceE/ReferenceFactory.h index ede23b67292..d867a926340 100644 --- a/cppe/src/IceE/ReferenceFactory.h +++ b/cppe/src/IceE/ReferenceFactory.h @@ -14,7 +14,7 @@ #include <IceE/ConnectionF.h> #include <IceE/Shared.h> #include <IceE/Mutex.h> -#include <IceE/Reference.h> // For Reference::Mode +#include <IceE/Reference.h> // For ReferenceMode namespace IceInternal { @@ -31,7 +31,7 @@ public: // // Create a direct reference. // - ReferencePtr create(const ::Ice::Identity&, const Ice::Context&, const ::std::string&, Reference::Mode, bool, + ReferencePtr create(const ::Ice::Identity&, const Ice::Context&, const ::std::string&, ReferenceMode, bool, const ::std::vector<EndpointPtr>& #ifdef ICEE_HAS_ROUTER , const RouterInfoPtr& @@ -41,7 +41,7 @@ public: // Create an indirect reference. // #ifdef ICEE_HAS_LOCATOR - ReferencePtr create(const ::Ice::Identity&, const Ice::Context&, const ::std::string&, Reference::Mode, bool, + ReferencePtr create(const ::Ice::Identity&, const Ice::Context&, const ::std::string&, ReferenceMode, bool, const ::std::string& #ifdef ICEE_HAS_ROUTER , const RouterInfoPtr& @@ -51,7 +51,7 @@ public: // // Create a fixed reference. // - ReferencePtr create(const ::Ice::Identity&, const Ice::Context&, const ::std::string&, Reference::Mode, + ReferencePtr create(const ::Ice::Identity&, const Ice::Context&, const ::std::string&, ReferenceMode, const ::std::vector< ::Ice::ConnectionPtr>&); // diff --git a/cppe/src/IceE/UnknownEndpoint.cpp b/cppe/src/IceE/UnknownEndpoint.cpp index bf6beb5d983..25673fd2f4a 100644 --- a/cppe/src/IceE/UnknownEndpoint.cpp +++ b/cppe/src/IceE/UnknownEndpoint.cpp @@ -161,6 +161,18 @@ IceInternal::UnknownEndpoint::timeout(Int) const } bool +IceInternal::UnknownEndpoint::secure() const +{ + return false; +} + +bool +IceInternal::UnknownEndpoint::datagram() const +{ + return false; +} + +bool IceInternal::UnknownEndpoint::unknown() const { return true; diff --git a/cppe/src/IceE/UnknownEndpoint.h b/cppe/src/IceE/UnknownEndpoint.h index 5ce05218bf9..6a2d9c4ac07 100644 --- a/cppe/src/IceE/UnknownEndpoint.h +++ b/cppe/src/IceE/UnknownEndpoint.h @@ -27,6 +27,8 @@ public: virtual Ice::Short type() const; virtual Ice::Int timeout() const; virtual EndpointPtr timeout(Ice::Int) const; + virtual bool secure() const; + virtual bool datagram() const; virtual bool unknown() const; virtual ConnectorPtr connector() const; #ifndef ICEE_PURE_CLIENT diff --git a/cppe/src/TcpTransport/EndpointFactory.cpp b/cppe/src/TcpTransport/EndpointFactory.cpp index f95bb72f9d8..612d1329764 100644 --- a/cppe/src/TcpTransport/EndpointFactory.cpp +++ b/cppe/src/TcpTransport/EndpointFactory.cpp @@ -69,9 +69,9 @@ IceInternal::EndpointFactory::create(const std::string& str) const // and ask the factory to read the endpoint data from that stream to create // the actual endpoint. // - BasicStream bs(_instance.get(), _instance->messageSizeMax(), + BasicStream bs(_instance.get(), _instance->messageSizeMax() #ifdef ICEE_HAS_WSTRING - _instance->initializationData().stringConverter, + , _instance->initializationData().stringConverter, _instance->initializationData().wstringConverter #endif ); diff --git a/cppe/src/TcpTransport/TcpEndpoint.cpp b/cppe/src/TcpTransport/TcpEndpoint.cpp index 4f09591f604..e41d7d2efe1 100644 --- a/cppe/src/TcpTransport/TcpEndpoint.cpp +++ b/cppe/src/TcpTransport/TcpEndpoint.cpp @@ -203,6 +203,18 @@ IceInternal::TcpEndpoint::timeout(Int timeout) const } bool +IceInternal::TcpEndpoint::secure() const +{ + return false; +} + +bool +IceInternal::TcpEndpoint::datagram() const +{ + return false; +} + +bool IceInternal::TcpEndpoint::unknown() const { return false; diff --git a/cppe/src/TcpTransport/TcpEndpoint.h b/cppe/src/TcpTransport/TcpEndpoint.h index e36802214e7..153a7701897 100644 --- a/cppe/src/TcpTransport/TcpEndpoint.h +++ b/cppe/src/TcpTransport/TcpEndpoint.h @@ -30,6 +30,8 @@ public: virtual Ice::Short type() const; virtual Ice::Int timeout() const; virtual EndpointPtr timeout(Ice::Int) const; + virtual bool secure() const; + virtual bool datagram() const; virtual bool unknown() const; virtual ConnectorPtr connector() const; #ifndef ICEE_PURE_CLIENT |