diff --git a/cpp/include/Ice/Proxy.h b/cpp/include/Ice/Proxy.h index b20a1704022..88a9d1d2773 100644 --- a/cpp/include/Ice/Proxy.h +++ b/cpp/include/Ice/Proxy.h @@ -15,6 +15,7 @@ #include "ReferenceF.h" #include "RequestHandlerF.h" +#include #include #include #include @@ -165,7 +166,22 @@ namespace Ice * @param timeout The new invocation timeout (in milliseconds). * @return A proxy with the new timeout. */ - Prx ice_invocationTimeout(int timeout) const { return fromReference(asPrx()._invocationTimeout(timeout)); } + Prx ice_invocationTimeout(int timeout) const + { + return ice_invocationTimeout(std::chrono::milliseconds(timeout)); + } + + /** + * Obtains a proxy that is identical to this proxy, except for the invocation timeout. + * @param timeout The new invocation timeout. + * @return A proxy with the new timeout. + */ + template + Prx ice_invocationTimeout(const std::chrono::duration& timeout) const + { + return fromReference( + asPrx()._invocationTimeout(std::chrono::duration_cast(timeout))); + } /** * Obtains a proxy that is identical to this proxy, except for the locator. @@ -182,7 +198,22 @@ namespace Ice * @param timeout The new locator cache timeout (in seconds). * @return A proxy with the new timeout. */ - Prx ice_locatorCacheTimeout(int timeout) const { return fromReference(asPrx()._locatorCacheTimeout(timeout)); } + Prx ice_locatorCacheTimeout(int timeout) const + { + return ice_locatorCacheTimeout(std::chrono::seconds(timeout)); + } + + /** + * Obtains a proxy that is identical to this proxy, except for the locator cache timeout. + * @param timeout The new locator cache timeout. + * @return A proxy with the new timeout. + */ + template + Prx ice_locatorCacheTimeout(const std::chrono::duration& timeout) const + { + return fromReference( + asPrx()._locatorCacheTimeout(std::chrono::duration_cast(timeout))); + } /** * Obtains a proxy that is identical to this proxy, but uses oneway invocations. @@ -614,9 +645,9 @@ namespace Ice /** * Obtains the locator cache timeout of this proxy. - * @return The locator cache timeout value (in seconds). + * @return The locator cache timeout value. */ - std::int32_t ice_getLocatorCacheTimeout() const noexcept; + std::chrono::milliseconds ice_getLocatorCacheTimeout() const noexcept; /** * Determines whether this proxy caches connections. @@ -670,9 +701,9 @@ namespace Ice /** * Obtains the invocation timeout of this proxy. - * @return The invocation timeout value (in milliseconds). + * @return The invocation timeout value. */ - std::int32_t ice_getInvocationTimeout() const noexcept; + std::chrono::milliseconds ice_getInvocationTimeout() const noexcept; /** * Determines whether this proxy uses twoway invocations. @@ -787,14 +818,13 @@ namespace Ice IceInternal::ReferencePtr _identity(Identity) const; IceInternal::ReferencePtr _facet(std::string) const; IceInternal::ReferencePtr _fixed(ConnectionPtr) const; - IceInternal::ReferencePtr _invocationTimeout(int) const; + IceInternal::ReferencePtr _invocationTimeout(std::chrono::milliseconds) const; IceInternal::ReferencePtr _locator(const std::optional&) const; - IceInternal::ReferencePtr _locatorCacheTimeout(int) const; + IceInternal::ReferencePtr _locatorCacheTimeout(std::chrono::milliseconds) const; IceInternal::ReferencePtr _oneway() const; IceInternal::ReferencePtr _preferSecure(bool) const; IceInternal::ReferencePtr _router(const std::optional&) const; IceInternal::ReferencePtr _secure(bool) const; - IceInternal::ReferencePtr _timeout(int) const; IceInternal::ReferencePtr _twoway() const; // Only the assignment operators can change these fields. All other member functions must be const. diff --git a/cpp/src/Ice/CollocatedRequestHandler.cpp b/cpp/src/Ice/CollocatedRequestHandler.cpp index dafbb232a0e..0554fb26adb 100644 --- a/cpp/src/Ice/CollocatedRequestHandler.cpp +++ b/cpp/src/Ice/CollocatedRequestHandler.cpp @@ -158,7 +158,7 @@ CollocatedRequestHandler::invokeAsyncRequest(OutgoingAsyncBase* outAsync, int ba // auto self = shared_from_this(); - if (!synchronous || !_response || _reference->getInvocationTimeout() > 0) + if (!synchronous || !_response || _reference->getInvocationTimeout() > 0ms) { auto stream = make_shared(); is.swap(*stream); diff --git a/cpp/src/Ice/DefaultsAndOverrides.cpp b/cpp/src/Ice/DefaultsAndOverrides.cpp index 19f5b613335..4cde22cc46b 100644 --- a/cpp/src/Ice/DefaultsAndOverrides.cpp +++ b/cpp/src/Ice/DefaultsAndOverrides.cpp @@ -11,7 +11,7 @@ using namespace std; using namespace Ice; using namespace IceInternal; -IceInternal::DefaultsAndOverrides::DefaultsAndOverrides(const PropertiesPtr& properties, const LoggerPtr& logger) +IceInternal::DefaultsAndOverrides::DefaultsAndOverrides(const PropertiesPtr& properties) : overrideCompress(nullopt), overrideSecure(nullopt) { @@ -63,23 +63,10 @@ IceInternal::DefaultsAndOverrides::DefaultsAndOverrides(const PropertiesPtr& pro throw ParseException(__FILE__, __LINE__, "illegal value '" + value + "'; expected 'Random' or 'Ordered'"); } - const_cast(defaultInvocationTimeout) = properties->getIcePropertyAsInt("Ice.Default.InvocationTimeout"); - if (defaultInvocationTimeout < 1 && defaultInvocationTimeout != -1) - { - const_cast(defaultInvocationTimeout) = -1; - Warning out(logger); - out << "invalid value for Ice.Default.InvocationTimeout `" - << properties->getIceProperty("Ice.Default.InvocationTimeout") << "': defaulting to -1"; - } - - const_cast(defaultLocatorCacheTimeout) = properties->getIcePropertyAsInt("Ice.Default.LocatorCacheTimeout"); - if (defaultLocatorCacheTimeout < -1) - { - const_cast(defaultLocatorCacheTimeout) = -1; - Warning out(logger); - out << "invalid value for Ice.Default.LocatorCacheTimeout `" - << properties->getIceProperty("Ice.Default.LocatorCacheTimeout") << "': defaulting to -1"; - } + const_cast(defaultInvocationTimeout) = + chrono::milliseconds(properties->getIcePropertyAsInt("Ice.Default.InvocationTimeout")); + const_cast(defaultLocatorCacheTimeout) = + chrono::seconds(properties->getIcePropertyAsInt("Ice.Default.LocatorCacheTimeout")); const_cast(defaultPreferSecure) = properties->getIcePropertyAsInt("Ice.Default.PreferSecure") > 0; diff --git a/cpp/src/Ice/DefaultsAndOverrides.h b/cpp/src/Ice/DefaultsAndOverrides.h index 46ca2499cac..f93fc9ec0b3 100644 --- a/cpp/src/Ice/DefaultsAndOverrides.h +++ b/cpp/src/Ice/DefaultsAndOverrides.h @@ -13,20 +13,22 @@ #include "Ice/PropertiesF.h" #include "Network.h" +#include + namespace IceInternal { class DefaultsAndOverrides { public: - DefaultsAndOverrides(const Ice::PropertiesPtr&, const Ice::LoggerPtr&); + DefaultsAndOverrides(const Ice::PropertiesPtr&); std::string defaultHost; Address defaultSourceAddress; std::string defaultProtocol; bool defaultCollocationOptimization; Ice::EndpointSelectionType defaultEndpointSelection; - int defaultInvocationTimeout; - int defaultLocatorCacheTimeout; + std::chrono::milliseconds defaultInvocationTimeout; + std::chrono::seconds defaultLocatorCacheTimeout; bool defaultPreferSecure; Ice::EncodingVersion defaultEncoding; Ice::FormatType defaultFormat; diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp index 9a5da5aa310..05cb9dc2431 100644 --- a/cpp/src/Ice/Instance.cpp +++ b/cpp/src/Ice/Instance.cpp @@ -1105,7 +1105,7 @@ IceInternal::Instance::initialize(const Ice::CommunicatorPtr& communicator) const_cast(_traceLevels) = make_shared(_initData.properties); const_cast(_defaultsAndOverrides) = - make_shared(_initData.properties, _initData.logger); + make_shared(_initData.properties); const_cast(_clientConnectionOptions) = readConnectionOptions("Ice.Connection.Client"); const_cast(_serverConnectionOptions) = readConnectionOptions("Ice.Connection.Server"); diff --git a/cpp/src/Ice/LocatorInfo.cpp b/cpp/src/Ice/LocatorInfo.cpp index a69077bc794..a10c90ec835 100644 --- a/cpp/src/Ice/LocatorInfo.cpp +++ b/cpp/src/Ice/LocatorInfo.cpp @@ -159,9 +159,12 @@ IceInternal::LocatorTable::clear() } bool -IceInternal::LocatorTable::getAdapterEndpoints(const string& adapter, int ttl, vector& endpoints) +IceInternal::LocatorTable::getAdapterEndpoints( + const string& adapter, + chrono::milliseconds ttl, + vector& endpoints) { - if (ttl == 0) // No locator cache. + if (ttl == 0ms) // No locator cache. { return false; } @@ -214,9 +217,9 @@ IceInternal::LocatorTable::removeAdapterEndpoints(const string& adapter) } bool -IceInternal::LocatorTable::getObjectReference(const Identity& id, int ttl, ReferencePtr& ref) +IceInternal::LocatorTable::getObjectReference(const Identity& id, chrono::milliseconds ttl, ReferencePtr& ref) { - if (ttl == 0) // No locator cache + if (ttl == 0ms) // No locator cache { return false; } @@ -266,16 +269,16 @@ IceInternal::LocatorTable::removeObjectReference(const Identity& id) } bool -IceInternal::LocatorTable::checkTTL(const chrono::steady_clock::time_point& time, int ttl) const +IceInternal::LocatorTable::checkTTL(const chrono::steady_clock::time_point& time, chrono::milliseconds ttl) const { - assert(ttl != 0); - if (ttl < 0) // TTL = infinite + assert(ttl != 0ms); + if (ttl < 0ms) // TTL = infinite { return true; } else { - return chrono::steady_clock::now() - time <= chrono::seconds(ttl); + return chrono::steady_clock::now() - time <= ttl; } } @@ -345,7 +348,7 @@ IceInternal::LocatorInfo::RequestCallback::exception(const LocatorInfoPtr& locat IceInternal::LocatorInfo::RequestCallback::RequestCallback( const ReferencePtr& ref, - int ttl, + chrono::milliseconds ttl, const GetEndpointsCallbackPtr& cb) : _reference(ref), _ttl(ttl), @@ -357,7 +360,7 @@ void IceInternal::LocatorInfo::Request::addCallback( const ReferencePtr& ref, const ReferencePtr& wellKnownRef, - int ttl, + chrono::milliseconds ttl, const GetEndpointsCallbackPtr& cb) { RequestCallbackPtr callback = make_shared(ref, ttl, cb); @@ -508,7 +511,7 @@ void IceInternal::LocatorInfo::getEndpoints( const ReferencePtr& ref, const ReferencePtr& wellKnownRef, - int ttl, + chrono::milliseconds ttl, const GetEndpointsCallbackPtr& callback) { assert(ref->isIndirect()); diff --git a/cpp/src/Ice/LocatorInfo.h b/cpp/src/Ice/LocatorInfo.h index a94317deb3d..1a809c5f297 100644 --- a/cpp/src/Ice/LocatorInfo.h +++ b/cpp/src/Ice/LocatorInfo.h @@ -48,16 +48,16 @@ namespace IceInternal void clear(); - bool getAdapterEndpoints(const std::string&, int, std::vector&); + bool getAdapterEndpoints(const std::string&, std::chrono::milliseconds, std::vector&); void addAdapterEndpoints(const std::string&, const std::vector&); std::vector removeAdapterEndpoints(const std::string&); - bool getObjectReference(const Ice::Identity&, int, ReferencePtr&); + bool getObjectReference(const Ice::Identity&, std::chrono::milliseconds, ReferencePtr&); void addObjectReference(const Ice::Identity&, const ReferencePtr&); ReferencePtr removeObjectReference(const Ice::Identity&); private: - bool checkTTL(const std::chrono::steady_clock::time_point&, int) const; + bool checkTTL(const std::chrono::steady_clock::time_point&, std::chrono::milliseconds) const; std::map>> _adapterEndpointsMap; @@ -79,14 +79,14 @@ namespace IceInternal class RequestCallback final { public: - RequestCallback(const ReferencePtr&, int, const GetEndpointsCallbackPtr&); + RequestCallback(const ReferencePtr&, std::chrono::milliseconds, const GetEndpointsCallbackPtr&); void response(const LocatorInfoPtr&, const std::optional&); void exception(const LocatorInfoPtr&, std::exception_ptr); private: const ReferencePtr _reference; - const int _ttl; + const std::chrono::milliseconds _ttl; const GetEndpointsCallbackPtr _callback; }; using RequestCallbackPtr = std::shared_ptr; @@ -94,7 +94,11 @@ namespace IceInternal class Request { public: - void addCallback(const ReferencePtr&, const ReferencePtr&, int, const GetEndpointsCallbackPtr&); + void addCallback( + const ReferencePtr&, + const ReferencePtr&, + std::chrono::milliseconds, + const GetEndpointsCallbackPtr&); void response(const std::optional&); void exception(std::exception_ptr); @@ -129,11 +133,15 @@ namespace IceInternal std::optional getLocatorRegistry(); - void getEndpoints(const ReferencePtr& ref, int ttl, const GetEndpointsCallbackPtr& cb) + void getEndpoints(const ReferencePtr& ref, std::chrono::milliseconds ttl, const GetEndpointsCallbackPtr& cb) { getEndpoints(ref, 0, ttl, cb); } - void getEndpoints(const ReferencePtr&, const ReferencePtr&, int, const GetEndpointsCallbackPtr&); + void getEndpoints( + const ReferencePtr&, + const ReferencePtr&, + std::chrono::milliseconds, + const GetEndpointsCallbackPtr&); void clearCache(const ReferencePtr&); diff --git a/cpp/src/Ice/OutgoingAsync.cpp b/cpp/src/Ice/OutgoingAsync.cpp index 61a5fb09fe6..a2303463b18 100644 --- a/cpp/src/Ice/OutgoingAsync.cpp +++ b/cpp/src/Ice/OutgoingAsync.cpp @@ -428,10 +428,10 @@ ProxyOutgoingAsyncBase::invokeImpl(bool userThread) { if (userThread) { - int invocationTimeout = _proxy._getReference()->getInvocationTimeout(); - if (invocationTimeout > 0) + chrono::milliseconds invocationTimeout = _proxy._getReference()->getInvocationTimeout(); + if (invocationTimeout > 0ms) { - _instance->timer()->schedule(shared_from_this(), chrono::milliseconds(invocationTimeout)); + _instance->timer()->schedule(shared_from_this(), invocationTimeout); } } else @@ -515,7 +515,7 @@ ProxyOutgoingAsyncBase::sentImpl(bool done) _sent = true; if (done) { - if (_proxy._getReference()->getInvocationTimeout() != -1) + if (_proxy._getReference()->getInvocationTimeout() > 0ms) { _instance->timer()->cancel(shared_from_this()); } @@ -526,7 +526,7 @@ ProxyOutgoingAsyncBase::sentImpl(bool done) bool ProxyOutgoingAsyncBase::exceptionImpl(std::exception_ptr ex) { - if (_proxy._getReference()->getInvocationTimeout() != -1) + if (_proxy._getReference()->getInvocationTimeout() > 0ms) { _instance->timer()->cancel(shared_from_this()); } @@ -536,7 +536,7 @@ ProxyOutgoingAsyncBase::exceptionImpl(std::exception_ptr ex) bool ProxyOutgoingAsyncBase::responseImpl(bool ok, bool invoke) { - if (_proxy._getReference()->getInvocationTimeout() != -1) + if (_proxy._getReference()->getInvocationTimeout() > 0ms) { _instance->timer()->cancel(shared_from_this()); } diff --git a/cpp/src/Ice/Proxy.cpp b/cpp/src/Ice/Proxy.cpp index cab8682c7b6..8f517edd929 100644 --- a/cpp/src/Ice/Proxy.cpp +++ b/cpp/src/Ice/Proxy.cpp @@ -109,7 +109,7 @@ Ice::ObjectPrx::ice_getEndpoints() const return retSeq; } -int32_t +chrono::milliseconds Ice::ObjectPrx::ice_getLocatorCacheTimeout() const noexcept { return _reference->getLocatorCacheTimeout(); @@ -165,7 +165,7 @@ Ice::ObjectPrx::ice_isCollocationOptimized() const noexcept return _reference->getCollocationOptimized(); } -int32_t +chrono::milliseconds Ice::ObjectPrx::ice_getInvocationTimeout() const noexcept { return _reference->getInvocationTimeout(); @@ -476,14 +476,8 @@ Ice::ObjectPrx::_fixed(ConnectionPtr connection) const } ReferencePtr -Ice::ObjectPrx::_invocationTimeout(int newTimeout) const +Ice::ObjectPrx::_invocationTimeout(chrono::milliseconds newTimeout) const { - if (newTimeout < 1 && newTimeout != -1) - { - ostringstream s; - s << "invalid value passed to ice_invocationTimeout: " << newTimeout; - throw invalid_argument(s.str()); - } if (newTimeout == _reference->getInvocationTimeout()) { return _reference; @@ -509,14 +503,8 @@ Ice::ObjectPrx::_locator(const std::optional& locator) const } ReferencePtr -Ice::ObjectPrx::_locatorCacheTimeout(int newTimeout) const +Ice::ObjectPrx::_locatorCacheTimeout(chrono::milliseconds newTimeout) const { - if (newTimeout < -1) - { - ostringstream s; - s << "invalid value passed to ice_locatorCacheTimeout: " << newTimeout; - throw invalid_argument(s.str()); - } if (newTimeout == _reference->getLocatorCacheTimeout()) { return _reference; diff --git a/cpp/src/Ice/Reference.cpp b/cpp/src/Ice/Reference.cpp index a664c93c81a..3848c228f85 100644 --- a/cpp/src/Ice/Reference.cpp +++ b/cpp/src/Ice/Reference.cpp @@ -81,7 +81,7 @@ IceInternal::Reference::changeFacet(string newFacet) const } ReferencePtr -IceInternal::Reference::changeInvocationTimeout(int invocationTimeout) const +IceInternal::Reference::changeInvocationTimeout(chrono::milliseconds invocationTimeout) const { ReferencePtr r = clone(); r->_invocationTimeout = invocationTimeout; @@ -125,7 +125,7 @@ Reference::hash() const noexcept hashAdd(h, _facet); hashAdd(h, _compress); // We don't include protocol and encoding in the hash; they are using 1.0 and 1.1, respectively. - hashAdd(h, _invocationTimeout); + hashAdd(h, _invocationTimeout.count()); return h; } @@ -430,7 +430,7 @@ IceInternal::Reference::Reference( std::optional compress, const ProtocolVersion& protocol, const EncodingVersion& encoding, - int invocationTimeout, + chrono::milliseconds invocationTimeout, const Ice::Context& ctx) : _instance(instance), _communicator(communicator), @@ -473,7 +473,7 @@ IceInternal::FixedReference::FixedReference( const ProtocolVersion& protocol, const EncodingVersion& encoding, ConnectionIPtr fixedConnection, - int invocationTimeout, + chrono::milliseconds invocationTimeout, const Ice::Context& context) : Reference( instance, @@ -527,10 +527,10 @@ IceInternal::FixedReference::getEndpointSelection() const noexcept return EndpointSelectionType::Random; } -int +chrono::milliseconds IceInternal::FixedReference::getLocatorCacheTimeout() const noexcept { - return 0; + return 0ms; } string @@ -588,7 +588,7 @@ IceInternal::FixedReference::changeEndpointSelection(EndpointSelectionType) cons } ReferencePtr -IceInternal::FixedReference::changeLocatorCacheTimeout(int) const +IceInternal::FixedReference::changeLocatorCacheTimeout(chrono::milliseconds) const { throw FixedProxyException(__FILE__, __LINE__); } @@ -765,8 +765,8 @@ IceInternal::RoutableReference::RoutableReference( bool cacheConnection, bool preferSecure, EndpointSelectionType endpointSelection, - int locatorCacheTimeout, - int invocationTimeout, + chrono::milliseconds locatorCacheTimeout, + chrono::milliseconds invocationTimeout, const Ice::Context& ctx) : Reference(instance, communicator, id, facet, mode, secure, compress, protocol, encoding, invocationTimeout, ctx), _endpoints(endpoints), @@ -831,7 +831,7 @@ IceInternal::RoutableReference::getEndpointSelection() const noexcept return _endpointSelection; } -int +chrono::milliseconds IceInternal::RoutableReference::getLocatorCacheTimeout() const noexcept { return _locatorCacheTimeout; @@ -953,7 +953,7 @@ IceInternal::RoutableReference::changeEndpointSelection(EndpointSelectionType ne } ReferencePtr -IceInternal::RoutableReference::changeLocatorCacheTimeout(int timeout) const +IceInternal::RoutableReference::changeLocatorCacheTimeout(chrono::milliseconds timeout) const { RoutableReferencePtr r = dynamic_pointer_cast(clone()); r->_locatorCacheTimeout = timeout; @@ -1092,8 +1092,9 @@ IceInternal::RoutableReference::toProperty(const string& prefix) const properties[prefix + ".PreferSecure"] = _preferSecure ? "1" : "0"; properties[prefix + ".EndpointSelection"] = _endpointSelection == EndpointSelectionType::Random ? "Random" : "Ordered"; - properties[prefix + ".LocatorCacheTimeout"] = to_string(_locatorCacheTimeout); - properties[prefix + ".InvocationTimeout"] = to_string(getInvocationTimeout()); + properties[prefix + ".LocatorCacheTimeout"] = + to_string(chrono::duration_cast(_locatorCacheTimeout).count()); + properties[prefix + ".InvocationTimeout"] = to_string(getInvocationTimeout().count()); if (_routerInfo) { diff --git a/cpp/src/Ice/Reference.h b/cpp/src/Ice/Reference.h index 681fc079f23..a2dc895064b 100644 --- a/cpp/src/Ice/Reference.h +++ b/cpp/src/Ice/Reference.h @@ -55,7 +55,7 @@ namespace IceInternal const std::string& getFacet() const noexcept { return _facet; } const InstancePtr& getInstance() const noexcept { return _instance; } const SharedContextPtr& getContext() const noexcept { return _context; } - int getInvocationTimeout() const noexcept { return _invocationTimeout; } + std::chrono::milliseconds getInvocationTimeout() const noexcept { return _invocationTimeout; } std::optional getCompress() const noexcept { return _compress; } Ice::CommunicatorPtr getCommunicator() const noexcept; @@ -68,7 +68,7 @@ namespace IceInternal virtual bool getCacheConnection() const noexcept = 0; virtual bool getPreferSecure() const noexcept = 0; virtual Ice::EndpointSelectionType getEndpointSelection() const noexcept = 0; - virtual int getLocatorCacheTimeout() const noexcept = 0; + virtual std::chrono::milliseconds getLocatorCacheTimeout() const noexcept = 0; virtual std::string getConnectionId() const = 0; // @@ -80,7 +80,7 @@ namespace IceInternal ReferencePtr changeSecure(bool) const; ReferencePtr changeIdentity(Ice::Identity) const; ReferencePtr changeFacet(std::string) const; - ReferencePtr changeInvocationTimeout(int) const; + ReferencePtr changeInvocationTimeout(std::chrono::milliseconds) const; virtual ReferencePtr changeEncoding(Ice::EncodingVersion) const; virtual ReferencePtr changeCompress(bool) const; @@ -90,7 +90,7 @@ namespace IceInternal virtual ReferencePtr changeLocator(std::optional) const = 0; virtual ReferencePtr changeRouter(std::optional) const = 0; virtual ReferencePtr changeCollocationOptimized(bool) const = 0; - virtual ReferencePtr changeLocatorCacheTimeout(int) const = 0; + virtual ReferencePtr changeLocatorCacheTimeout(std::chrono::milliseconds) const = 0; virtual ReferencePtr changeCacheConnection(bool) const = 0; virtual ReferencePtr changePreferSecure(bool) const = 0; virtual ReferencePtr changeEndpointSelection(Ice::EndpointSelectionType) const = 0; @@ -150,7 +150,7 @@ namespace IceInternal std::optional, const Ice::ProtocolVersion&, const Ice::EncodingVersion&, - int, + std::chrono::milliseconds, const Ice::Context& ctx); Reference(const Reference&); @@ -167,7 +167,7 @@ namespace IceInternal std::string _facet; Ice::ProtocolVersion _protocol; Ice::EncodingVersion _encoding; - int _invocationTimeout; + std::chrono::milliseconds _invocationTimeout; }; class FixedReference final : public Reference @@ -184,7 +184,7 @@ namespace IceInternal const Ice::ProtocolVersion&, const Ice::EncodingVersion&, Ice::ConnectionIPtr, - int, + std::chrono::milliseconds, const Ice::Context&); FixedReference(const FixedReference&); @@ -195,7 +195,7 @@ namespace IceInternal bool getCacheConnection() const noexcept final; bool getPreferSecure() const noexcept final; Ice::EndpointSelectionType getEndpointSelection() const noexcept final; - int getLocatorCacheTimeout() const noexcept final; + std::chrono::milliseconds getLocatorCacheTimeout() const noexcept final; std::string getConnectionId() const final; ReferencePtr changeEndpoints(std::vector) const final; @@ -206,7 +206,7 @@ namespace IceInternal ReferencePtr changeCacheConnection(bool) const final; ReferencePtr changePreferSecure(bool) const final; ReferencePtr changeEndpointSelection(Ice::EndpointSelectionType) const final; - ReferencePtr changeLocatorCacheTimeout(int) const final; + ReferencePtr changeLocatorCacheTimeout(std::chrono::milliseconds) const final; ReferencePtr changeConnectionId(std::string) const final; ReferencePtr changeConnection(Ice::ConnectionIPtr) const final; @@ -252,8 +252,8 @@ namespace IceInternal bool, bool, Ice::EndpointSelectionType, - int, - int, + std::chrono::milliseconds, + std::chrono::milliseconds, const Ice::Context&); RoutableReference(const RoutableReference&); @@ -266,7 +266,7 @@ namespace IceInternal bool getCacheConnection() const noexcept final; bool getPreferSecure() const noexcept final; Ice::EndpointSelectionType getEndpointSelection() const noexcept final; - int getLocatorCacheTimeout() const noexcept final; + std::chrono::milliseconds getLocatorCacheTimeout() const noexcept final; std::string getConnectionId() const final; ReferencePtr changeEncoding(Ice::EncodingVersion) const final; @@ -280,7 +280,7 @@ namespace IceInternal ReferencePtr changeCacheConnection(bool) const final; ReferencePtr changePreferSecure(bool) const final; ReferencePtr changeEndpointSelection(Ice::EndpointSelectionType) const final; - ReferencePtr changeLocatorCacheTimeout(int) const final; + ReferencePtr changeLocatorCacheTimeout(std::chrono::milliseconds) const final; ReferencePtr changeConnectionId(std::string) const final; ReferencePtr changeConnection(Ice::ConnectionIPtr) const final; @@ -335,7 +335,7 @@ namespace IceInternal bool _cacheConnection; bool _preferSecure; Ice::EndpointSelectionType _endpointSelection; - int _locatorCacheTimeout; + std::chrono::milliseconds _locatorCacheTimeout; std::string _connectionId; }; diff --git a/cpp/src/Ice/ReferenceFactory.cpp b/cpp/src/Ice/ReferenceFactory.cpp index 06031a2e689..9dc405137f2 100644 --- a/cpp/src/Ice/ReferenceFactory.cpp +++ b/cpp/src/Ice/ReferenceFactory.cpp @@ -21,6 +21,7 @@ #include "PropertyNames.h" #include "RouterInfo.h" +#include #include using namespace std; @@ -88,7 +89,7 @@ IceInternal::ReferenceFactory::create(const Identity& ident, const Ice::Connecti Ice::Protocol_1_0, _instance->defaultsAndOverrides()->defaultEncoding, connection, - -1, + -1ms, Ice::Context()); } @@ -774,8 +775,8 @@ IceInternal::ReferenceFactory::create( bool cacheConnection = true; bool preferSecure = defaultsAndOverrides->defaultPreferSecure; Ice::EndpointSelectionType endpointSelection = defaultsAndOverrides->defaultEndpointSelection; - int locatorCacheTimeout = defaultsAndOverrides->defaultLocatorCacheTimeout; - int invocationTimeout = defaultsAndOverrides->defaultInvocationTimeout; + chrono::seconds locatorCacheTimeout = defaultsAndOverrides->defaultLocatorCacheTimeout; + chrono::milliseconds invocationTimeout = defaultsAndOverrides->defaultInvocationTimeout; Ice::Context ctx; // @@ -852,34 +853,12 @@ IceInternal::ReferenceFactory::create( } property = propertyPrefix + ".LocatorCacheTimeout"; - string value = properties->getProperty(property); - if (!value.empty()) - { - locatorCacheTimeout = properties->getPropertyAsIntWithDefault(property, locatorCacheTimeout); - if (locatorCacheTimeout < -1) - { - locatorCacheTimeout = -1; - - Warning out(_instance->initializationData().logger); - out << "invalid value for " << property << "'" << properties->getProperty(property) << "'" - << ": defaulting to -1"; - } - } + locatorCacheTimeout = chrono::seconds( + properties->getPropertyAsIntWithDefault(property, static_cast(locatorCacheTimeout.count()))); property = propertyPrefix + ".InvocationTimeout"; - value = properties->getProperty(property); - if (!value.empty()) - { - invocationTimeout = properties->getPropertyAsIntWithDefault(property, invocationTimeout); - if (invocationTimeout < 1 && invocationTimeout != -1) - { - invocationTimeout = -1; - - Warning out(_instance->initializationData().logger); - out << "invalid value for " << property << "'" << properties->getProperty(property) << "'" - << ": defaulting to -1"; - } - } + invocationTimeout = chrono::milliseconds( + properties->getPropertyAsIntWithDefault(property, static_cast(invocationTimeout.count()))); property = propertyPrefix + ".Context."; PropertyDict contexts = properties->getPropertiesForPrefix(property); diff --git a/cpp/src/IceGrid/AdminI.cpp b/cpp/src/IceGrid/AdminI.cpp index 52b367dab4d..d2ebd0a609a 100644 --- a/cpp/src/IceGrid/AdminI.cpp +++ b/cpp/src/IceGrid/AdminI.cpp @@ -93,17 +93,9 @@ namespace Ice::noExplicitContext); } - void useActivationTimeout() - { - auto timeout = secondsToInt(_activationTimeout) * 1000; - _proxy = _proxy->ice_invocationTimeout(timeout); - } + void useActivationTimeout() { _proxy = _proxy->ice_invocationTimeout(_activationTimeout); } - void useDeactivationTimeout() - { - auto timeout = secondsToInt(_deactivationTimeout) * 1000; - _proxy = _proxy->ice_invocationTimeout(timeout); - } + void useDeactivationTimeout() { _proxy = _proxy->ice_invocationTimeout(_deactivationTimeout); } ServerPrx* operator->() { return &_proxy; } diff --git a/cpp/src/IceGrid/IceGridNode.cpp b/cpp/src/IceGrid/IceGridNode.cpp index 587ffaa7077..99499eac4f8 100644 --- a/cpp/src/IceGrid/IceGridNode.cpp +++ b/cpp/src/IceGrid/IceGridNode.cpp @@ -464,7 +464,7 @@ NodeService::startImpl(int argc, char* argv[], int& status) { try { - communicator()->getDefaultLocator()->ice_invocationTimeout(1000)->ice_ping(); + communicator()->getDefaultLocator()->ice_invocationTimeout(1s)->ice_ping(); } catch (const Ice::Exception& ex) { diff --git a/cpp/src/IceGrid/LocatorI.cpp b/cpp/src/IceGrid/LocatorI.cpp index 7aaaa66dfb2..ec948c8e8cf 100644 --- a/cpp/src/IceGrid/LocatorI.cpp +++ b/cpp/src/IceGrid/LocatorI.cpp @@ -917,11 +917,11 @@ LocatorI::getDirectProxyException(const LocatorAdapterInfo& adapter, exception_p request->activating(adapter.id); } - int timeout = secondsToInt(adapter.activationTimeout + adapter.deactivationTimeout) * 1000; auto self = shared_from_this(); - adapter.proxy->ice_invocationTimeout(timeout)->activateAsync( - [self, adapter](auto obj) { self->getDirectProxyResponse(adapter, std::move(obj)); }, - [self, adapter](auto e) { self->getDirectProxyException(adapter, e); }); + adapter.proxy->ice_invocationTimeout(adapter.activationTimeout + adapter.deactivationTimeout) + ->activateAsync( + [self, adapter](auto obj) { self->getDirectProxyResponse(adapter, std::move(obj)); }, + [self, adapter](auto e) { self->getDirectProxyException(adapter, e); }); } else { diff --git a/cpp/src/IceGrid/NodeCache.cpp b/cpp/src/IceGrid/NodeCache.cpp index f9dde9ad999..2efe8e259f4 100644 --- a/cpp/src/IceGrid/NodeCache.cpp +++ b/cpp/src/IceGrid/NodeCache.cpp @@ -334,8 +334,7 @@ NodeEntry::loadServer( // if (timeout > 0s) { - auto timeoutInMilliseconds = secondsToInt(timeout) * 1000; - node = node->ice_invocationTimeout(std::move(timeoutInMilliseconds)); + node = node->ice_invocationTimeout(timeout); } ServerInfo info = server; @@ -467,8 +466,7 @@ NodeEntry::destroyServer( // if (timeout > 0s) { - int timeoutInMilliseconds = secondsToInt(timeout) * 1000; - node = node->ice_invocationTimeout(timeoutInMilliseconds); + node = node->ice_invocationTimeout(timeout); } } diff --git a/cpp/src/IceGrid/RegistryI.cpp b/cpp/src/IceGrid/RegistryI.cpp index 0089293542f..10e3b8fc2a6 100644 --- a/cpp/src/IceGrid/RegistryI.cpp +++ b/cpp/src/IceGrid/RegistryI.cpp @@ -323,7 +323,7 @@ RegistryI::startImpl() { string endpoints = properties->getProperty("IceGrid.Registry.Client.Endpoints"); string strPrx = _instanceName + "/Locator:" + endpoints; - _communicator->stringToProxy(strPrx)->ice_invocationTimeout(5000)->ice_ping(); + _communicator->stringToProxy(strPrx)->ice_invocationTimeout(5s)->ice_ping(); Error out(_communicator->getLogger()); out << "an IceGrid registry is already running and listening on the client endpoints `" << endpoints << "'"; diff --git a/cpp/src/IceGrid/Util.cpp b/cpp/src/IceGrid/Util.cpp index 6ffcbec9698..1ae21618e8a 100644 --- a/cpp/src/IceGrid/Util.cpp +++ b/cpp/src/IceGrid/Util.cpp @@ -363,7 +363,7 @@ IceGrid::getMMVersion(const string& o) int IceGrid::secondsToInt(const std::chrono::seconds& sec) { - return chrono::duration_cast>(sec).count(); + return static_cast(sec.count()); } void diff --git a/cpp/src/IceStorm/Subscriber.cpp b/cpp/src/IceStorm/Subscriber.cpp index f0d5a5ef4a3..ca73a184b80 100644 --- a/cpp/src/IceStorm/Subscriber.cpp +++ b/cpp/src/IceStorm/Subscriber.cpp @@ -297,8 +297,8 @@ namespace { SubscriberLink::SubscriberLink(const shared_ptr& instance, const SubscriberRecord& rec) : Subscriber(instance, rec, nullopt, -1, 1), - _obj(Ice::uncheckedCast(rec.obj->ice_collocationOptimized(false)->ice_invocationTimeout( - static_cast(instance->sendTimeout().count())))) + _obj(Ice::uncheckedCast( + rec.obj->ice_collocationOptimized(false)->ice_invocationTimeout(instance->sendTimeout()))) { } @@ -414,7 +414,7 @@ Subscriber::create(const shared_ptr& instance, const SubscriberRecord& optional newObj; try { - newObj = rec.obj->ice_invocationTimeout(static_cast(instance->sendTimeout().count())); + newObj = rec.obj->ice_invocationTimeout(instance->sendTimeout()); } catch (const Ice::FixedProxyException&) { diff --git a/cpp/test/Ice/location/AllTests.cpp b/cpp/test/Ice/location/AllTests.cpp index 4160f2d1fc7..0a96e77d915 100644 --- a/cpp/test/Ice/location/AllTests.cpp +++ b/cpp/test/Ice/location/AllTests.cpp @@ -270,7 +270,7 @@ allTests(Test::TestHelper* helper, const string& ref) ObjectPrx(communicator, "test")->ice_ping(); test(count == locator->getRequestCount()); - test(ObjectPrx(communicator, "test")->ice_locatorCacheTimeout(99)->ice_getLocatorCacheTimeout() == 99); + test(ObjectPrx(communicator, "test")->ice_locatorCacheTimeout(99)->ice_getLocatorCacheTimeout() == 99s); cout << "ok" << endl; diff --git a/cpp/test/Ice/proxy/AllTests.cpp b/cpp/test/Ice/proxy/AllTests.cpp index d569975f78e..c041a2d774c 100644 --- a/cpp/test/Ice/proxy/AllTests.cpp +++ b/cpp/test/Ice/proxy/AllTests.cpp @@ -455,10 +455,10 @@ allTests(TestHelper* helper) prop->setProperty(property, ""); property = propertyPrefix + ".LocatorCacheTimeout"; - test(b1->ice_getLocatorCacheTimeout() == -1); + test(b1->ice_getLocatorCacheTimeout() == -1s); prop->setProperty(property, "1"); b1 = communicator->propertyToProxy(propertyPrefix); - test(b1->ice_getLocatorCacheTimeout() == 1); + test(b1->ice_getLocatorCacheTimeout() == 1s); prop->setProperty(property, ""); // Now retest with an indirect proxy. @@ -470,10 +470,10 @@ allTests(TestHelper* helper) prop->setProperty(property, ""); property = propertyPrefix + ".LocatorCacheTimeout"; - test(b1->ice_getLocatorCacheTimeout() == -1); + test(b1->ice_getLocatorCacheTimeout() == -1s); prop->setProperty(property, "1"); b1 = communicator->propertyToProxy(propertyPrefix); - test(b1->ice_getLocatorCacheTimeout() == 1); + test(b1->ice_getLocatorCacheTimeout() == 1s); prop->setProperty(property, ""); // This cannot be tested so easily because the property is cached @@ -508,10 +508,10 @@ allTests(TestHelper* helper) prop->setProperty(property, ""); property = propertyPrefix + ".InvocationTimeout"; - test(b1->ice_getInvocationTimeout() == -1); + test(b1->ice_getInvocationTimeout() == -1ms); prop->setProperty(property, "1000"); b1 = communicator->propertyToProxy(propertyPrefix); - test(b1->ice_getInvocationTimeout() == 1000); + test(b1->ice_getInvocationTimeout() == 1s); prop->setProperty(property, ""); property = propertyPrefix + ".EndpointSelection"; @@ -635,59 +635,27 @@ allTests(TestHelper* helper) test(base->ice_encodingVersion(Ice::Encoding_1_1)->ice_getEncodingVersion() == Ice::Encoding_1_1); test(base->ice_encodingVersion(Ice::Encoding_1_0)->ice_getEncodingVersion() != Ice::Encoding_1_1); - try - { - base->ice_invocationTimeout(0); - test(false); - } - catch (const invalid_argument&) - { - } + test(base->ice_invocationTimeout(10)->ice_getInvocationTimeout() == 10ms); - try - { - base->ice_invocationTimeout(-1); - } - catch (const invalid_argument&) - { - test(false); - } + test(base->ice_invocationTimeout(0)->ice_getInvocationTimeout() == 0ms); + test(base->ice_invocationTimeout(0ms)->ice_getInvocationTimeout() == 0ms); - try - { - base->ice_invocationTimeout(-2); - test(false); - } - catch (const invalid_argument&) - { - } + test(base->ice_invocationTimeout(-1)->ice_getInvocationTimeout() == -1ms); + test(base->ice_invocationTimeout(-1ms)->ice_getInvocationTimeout() == -1ms); - try - { - base->ice_locatorCacheTimeout(0); - } - catch (const invalid_argument&) - { - test(false); - } + test(base->ice_invocationTimeout(-2)->ice_getInvocationTimeout() == -2ms); + test(base->ice_invocationTimeout(-2ms)->ice_getInvocationTimeout() == -2ms); - try - { - base->ice_locatorCacheTimeout(-1); - } - catch (const invalid_argument&) - { - test(false); - } + test(base->ice_locatorCacheTimeout(10)->ice_getLocatorCacheTimeout() == 10s); - try - { - base->ice_locatorCacheTimeout(-2); - test(false); - } - catch (const invalid_argument&) - { - } + test(base->ice_locatorCacheTimeout(0)->ice_getLocatorCacheTimeout() == 0s); + test(base->ice_locatorCacheTimeout(0s)->ice_getLocatorCacheTimeout() == 0s); + + test(base->ice_locatorCacheTimeout(-1)->ice_getLocatorCacheTimeout() == -1s); + test(base->ice_locatorCacheTimeout(-1s)->ice_getLocatorCacheTimeout() == -1s); + + test(base->ice_locatorCacheTimeout(-2)->ice_getLocatorCacheTimeout() == -2s); + test(base->ice_locatorCacheTimeout(-2s)->ice_getLocatorCacheTimeout() == -2s); cout << "ok" << endl; @@ -922,8 +890,8 @@ allTests(TestHelper* helper) ctx["two"] = "world"; test(cl->ice_fixed(connection)->ice_getContext().empty()); test(cl->ice_context(ctx)->ice_fixed(connection)->ice_getContext().size() == 2); - test(cl->ice_fixed(connection)->ice_getInvocationTimeout() == -1); - test(cl->ice_invocationTimeout(10)->ice_fixed(connection)->ice_getInvocationTimeout() == 10); + test(cl->ice_fixed(connection)->ice_getInvocationTimeout() == -1ms); + test(cl->ice_invocationTimeout(10)->ice_fixed(connection)->ice_getInvocationTimeout() == 10ms); test(cl->ice_fixed(connection)->ice_getConnection() == connection); test(cl->ice_fixed(connection)->ice_fixed(connection)->ice_getConnection() == connection); test(*cl->ice_compress(true)->ice_fixed(connection)->ice_getCompress()); @@ -1234,7 +1202,6 @@ allTests(TestHelper* helper) // Test with WS endpoint p = communicator->stringToProxy("test -t -e 1.0:ws -h localhost -p 10001 -t 20000 -r /path"); pstr = communicator->proxyToString(p); - cerr << pstr << endl; test(pstr == "test -t -e 1.0:ws -h localhost -p 10001 -t 20000 -r /path"); } std::locale::global(currentLocale); diff --git a/matlab/src/ObjectPrx.cpp b/matlab/src/ObjectPrx.cpp index 45e3cad7292..b908234b785 100644 --- a/matlab/src/ObjectPrx.cpp +++ b/matlab/src/ObjectPrx.cpp @@ -542,7 +542,9 @@ extern "C" mxArray* Ice_ObjectPrx_ice_getLocatorCacheTimeout(void* self) { - return createResultValue(createInt(restoreProxy(self)->ice_getLocatorCacheTimeout())); + chrono::seconds timeout = + chrono::duration_cast(restoreProxy(self)->ice_getLocatorCacheTimeout()); + return createResultValue(createInt(static_cast(timeout.count()))); } mxArray* Ice_ObjectPrx_ice_locatorCacheTimeout(void* self, void** r, int t) @@ -562,7 +564,8 @@ extern "C" mxArray* Ice_ObjectPrx_ice_getInvocationTimeout(void* self) { - return createResultValue(createInt(restoreProxy(self)->ice_getInvocationTimeout())); + chrono::milliseconds timeout = restoreProxy(self)->ice_getInvocationTimeout(); + return createResultValue(createInt(static_cast(timeout.count()))); } mxArray* Ice_ObjectPrx_ice_invocationTimeout(void* self, void** r, int t) diff --git a/php/src/Proxy.cpp b/php/src/Proxy.cpp index 1d0f8815656..f1381101b70 100644 --- a/php/src/Proxy.cpp +++ b/php/src/Proxy.cpp @@ -420,8 +420,8 @@ ZEND_METHOD(Ice_ObjectPrx, ice_getLocatorCacheTimeout) try { - int32_t timeout = _this->proxy->ice_getLocatorCacheTimeout(); - ZVAL_LONG(return_value, static_cast(timeout)); + chrono::seconds timeout = chrono::duration_cast(_this->proxy->ice_getLocatorCacheTimeout()); + ZVAL_LONG(return_value, static_cast(timeout.count())); } catch (...) { @@ -1253,7 +1253,8 @@ ZEND_METHOD(Ice_ObjectPrx, ice_getInvocationTimeout) try { - ZVAL_LONG(return_value, static_cast(_this->proxy->ice_getInvocationTimeout())); + chrono::milliseconds timeout = _this->proxy->ice_getInvocationTimeout(); + ZVAL_LONG(return_value, static_cast(timeout.count())); } catch (...) { diff --git a/python/modules/IcePy/Proxy.cpp b/python/modules/IcePy/Proxy.cpp index 3705829d991..f463524c185 100644 --- a/python/modules/IcePy/Proxy.cpp +++ b/python/modules/IcePy/Proxy.cpp @@ -611,8 +611,8 @@ proxyIceGetLocatorCacheTimeout(ProxyObject* self, PyObject* /*args*/) try { - int32_t timeout = (*self->proxy)->ice_getLocatorCacheTimeout(); - return PyLong_FromLong(timeout); + chrono::seconds timeout = chrono::duration_cast((*self->proxy)->ice_getLocatorCacheTimeout()); + return PyLong_FromLong(static_cast(timeout.count())); } catch (...) { @@ -628,8 +628,8 @@ proxyIceGetInvocationTimeout(ProxyObject* self, PyObject* /*args*/) try { - int32_t timeout = (*self->proxy)->ice_getInvocationTimeout(); - return PyLong_FromLong(timeout); + chrono::milliseconds timeout = (*self->proxy)->ice_getInvocationTimeout(); + return PyLong_FromLong(static_cast(timeout.count())); } catch (...) { diff --git a/ruby/src/IceRuby/Proxy.cpp b/ruby/src/IceRuby/Proxy.cpp index b7b8caf5810..cf64b259330 100644 --- a/ruby/src/IceRuby/Proxy.cpp +++ b/ruby/src/IceRuby/Proxy.cpp @@ -366,8 +366,8 @@ IceRuby_ObjectPrx_ice_getLocatorCacheTimeout(VALUE self) ICE_RUBY_TRY { Ice::ObjectPrx p = getProxy(self); - int32_t t = p->ice_getLocatorCacheTimeout(); - return INT2FIX(t); + chrono::seconds timeout = chrono::duration_cast(p->ice_getLocatorCacheTimeout()); + return INT2FIX(static_cast(timeout.count())); } ICE_RUBY_CATCH return Qnil; @@ -379,8 +379,8 @@ IceRuby_ObjectPrx_ice_getInvocationTimeout(VALUE self) ICE_RUBY_TRY { Ice::ObjectPrx p = getProxy(self); - int32_t t = p->ice_getInvocationTimeout(); - return INT2FIX(t); + chrono::milliseconds timeout = p->ice_getInvocationTimeout(); + return INT2FIX(static_cast(timeout.count())); } ICE_RUBY_CATCH return Qnil; diff --git a/swift/src/IceImpl/ObjectPrx.mm b/swift/src/IceImpl/ObjectPrx.mm index 182b80cee82..cb43caf5636 100644 --- a/swift/src/IceImpl/ObjectPrx.mm +++ b/swift/src/IceImpl/ObjectPrx.mm @@ -5,6 +5,7 @@ #import "include/Communicator.h" #import "include/Connection.h" #import "include/OutputStream.h" +#include @implementation ICEObjectPrx @@ -125,7 +126,8 @@ - (instancetype)ice_endpoints:(NSArray*)endpoints error:(NSError** - (int32_t)ice_getLocatorCacheTimeout { - return _prx->ice_getLocatorCacheTimeout(); + std::chrono::seconds timeout = std::chrono::duration_cast(_prx->ice_getLocatorCacheTimeout()); + return static_cast(timeout.count()); } - (instancetype)ice_locatorCacheTimeout:(int32_t)timeout error:(NSError**)error @@ -144,7 +146,7 @@ - (instancetype)ice_locatorCacheTimeout:(int32_t)timeout error:(NSError**)error - (int32_t)ice_getInvocationTimeout { - return _prx->ice_getInvocationTimeout(); + return static_cast(_prx->ice_getInvocationTimeout().count()); } - (instancetype)ice_invocationTimeout:(int32_t)timeout error:(NSError**)error