Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into x-buffered
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier committed Sep 27, 2024
2 parents f39189b + aa38119 commit 1ae33ad
Show file tree
Hide file tree
Showing 61 changed files with 471 additions and 654 deletions.
8 changes: 1 addition & 7 deletions config/PropertyNames.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ For example, consider the following definitions:
<properties>
<section name="Ice">
<property name="ChangeUser" />
<property name="Package.[any]" />
<property name="QuenchRequests" deprecated="true" />
<property name="Bar" />
Expand Down Expand Up @@ -149,7 +148,6 @@ public:
// Properties.cpp
const IceInternal::Property IceInternal::Properties::IcePropsData[] =
{
IceInternal::Property("Ice.ChangeUser", false, 0),
IceInternal::Property("Ice.Package.*", false, 0),
IceInternal::Property("Ice.QuenchRequests", true, 0),
IceInternal::Property("Ice.Foo", true, "Ice.Bar"),
Expand Down Expand Up @@ -220,11 +218,9 @@ generated from the section label.
<suffix name="Size" languages="cpp,csharp,java" default="1" />
<suffix name="SizeMax" languages="cpp,csharp,java" />
<suffix name="SizeWarn" languages="cpp,csharp,java" default="0" />
<!-- TODO: remove from c++ -->
<suffix name="StackSize" languages="csharp,java" default="0" />
<suffix name="Serialize" languages="cpp,csharp,java" default="0" />
<suffix name="ThreadIdleTime" languages="cpp,csharp,java" default="60" />
<!-- TODO: remove from c++ -->
<suffix name="ThreadPriority" languages="csharp,java" />
</class>

Expand Down Expand Up @@ -264,7 +260,6 @@ generated from the section label.
<property name="BackgroundLocatorCacheUpdates" languages="all" default="0" />
<property name="BatchAutoFlush" deprecated="true" languages="all" />
<property name="BatchAutoFlushSize" default="1024" languages="all" />
<property name="ChangeUser" languages="cpp" />
<property name="ClassGraphDepthMax" languages="all" default="10" />
<property name="Compression.Level" languages="cpp,csharp,java" default="1" />
<property name="Config" languages="cpp,csharp,java" />
Expand Down Expand Up @@ -316,8 +311,7 @@ generated from the section label.
<property name="SyslogFacility" languages="cpp,java" default="LOG_USER" />
<property name="ThreadPool.Client" class="threadpool" languages="cpp,csharp,java" />
<property name="ThreadPool.Server" class="threadpool" languages="cpp,csharp,java" />
<!-- TODO: remove from c++ -->
<property name="ThreadPriority" languages="cpp,csharp,java" />
<property name="ThreadPriority" languages="csharp,java" />
<property name="ToStringMode" languages="all" default="Unicode" />
<property name="Trace.Admin.Properties" languages="cpp,csharp,java" default="0" />
<property name="Trace.Admin.Logger" languages="cpp,csharp,java" default="0" />
Expand Down
48 changes: 39 additions & 9 deletions cpp/include/Ice/Proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "ReferenceF.h"
#include "RequestHandlerF.h"

#include <chrono>
#include <future>
#include <iosfwd>
#include <optional>
Expand Down Expand Up @@ -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<class Rep, class Period>
Prx ice_invocationTimeout(const std::chrono::duration<Rep, Period>& timeout) const
{
return fromReference(
asPrx()._invocationTimeout(std::chrono::duration_cast<std::chrono::milliseconds>(timeout)));
}

/**
* Obtains a proxy that is identical to this proxy, except for the locator.
Expand All @@ -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<class Rep, class Period>
Prx ice_locatorCacheTimeout(const std::chrono::duration<Rep, Period>& timeout) const
{
return fromReference(
asPrx()._locatorCacheTimeout(std::chrono::duration_cast<std::chrono::seconds>(timeout)));
}

/**
* Obtains a proxy that is identical to this proxy, but uses oneway invocations.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<LocatorPrx>&) 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<RouterPrx>&) 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.
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/CollocatedRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<InputStream>();
is.swap(*stream);
Expand Down
23 changes: 5 additions & 18 deletions cpp/src/Ice/DefaultsAndOverrides.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -63,23 +63,10 @@ IceInternal::DefaultsAndOverrides::DefaultsAndOverrides(const PropertiesPtr& pro
throw ParseException(__FILE__, __LINE__, "illegal value '" + value + "'; expected 'Random' or 'Ordered'");
}

const_cast<int&>(defaultInvocationTimeout) = properties->getIcePropertyAsInt("Ice.Default.InvocationTimeout");
if (defaultInvocationTimeout < 1 && defaultInvocationTimeout != -1)
{
const_cast<int32_t&>(defaultInvocationTimeout) = -1;
Warning out(logger);
out << "invalid value for Ice.Default.InvocationTimeout `"
<< properties->getIceProperty("Ice.Default.InvocationTimeout") << "': defaulting to -1";
}

const_cast<int&>(defaultLocatorCacheTimeout) = properties->getIcePropertyAsInt("Ice.Default.LocatorCacheTimeout");
if (defaultLocatorCacheTimeout < -1)
{
const_cast<int32_t&>(defaultLocatorCacheTimeout) = -1;
Warning out(logger);
out << "invalid value for Ice.Default.LocatorCacheTimeout `"
<< properties->getIceProperty("Ice.Default.LocatorCacheTimeout") << "': defaulting to -1";
}
const_cast<chrono::milliseconds&>(defaultInvocationTimeout) =
chrono::milliseconds(properties->getIcePropertyAsInt("Ice.Default.InvocationTimeout"));
const_cast<chrono::seconds&>(defaultLocatorCacheTimeout) =
chrono::seconds(properties->getIcePropertyAsInt("Ice.Default.LocatorCacheTimeout"));

const_cast<bool&>(defaultPreferSecure) = properties->getIcePropertyAsInt("Ice.Default.PreferSecure") > 0;

Expand Down
8 changes: 5 additions & 3 deletions cpp/src/Ice/DefaultsAndOverrides.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@
#include "Ice/PropertiesF.h"
#include "Network.h"

#include <chrono>

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;
Expand Down
41 changes: 1 addition & 40 deletions cpp/src/Ice/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -967,45 +967,6 @@ IceInternal::Instance::initialize(const Ice::CommunicatorPtr& communicator)
IceInternal::printStackTraces = false;
}
#endif

#ifndef _WIN32
string newUser = _initData.properties->getIceProperty("Ice.ChangeUser");
if (!newUser.empty())
{
struct passwd pwbuf;
vector<char> buffer(4096); // 4KB initial buffer
struct passwd* pw;
int err;
while ((err = getpwnam_r(newUser.c_str(), &pwbuf, &buffer[0], buffer.size(), &pw)) == ERANGE &&
buffer.size() < 1024 * 1024) // Limit buffer to 1M
{
buffer.resize(buffer.size() * 2);
}
if (err != 0)
{
throw Ice::SyscallException{__FILE__, __LINE__, "getpwnam_r failed", err};
}
else if (pw == 0)
{
throw InitializationException(__FILE__, __LINE__, "unknown user account '" + newUser + "'");
}

if (setgid(pw->pw_gid) == -1)
{
throw SyscallException{__FILE__, __LINE__, "setgid failed", errno};
}

if (initgroups(pw->pw_name, static_cast<int>(pw->pw_gid)) == -1)
{
throw SyscallException{__FILE__, __LINE__, "initgroups failed", errno};
}

if (setuid(pw->pw_uid) == -1)
{
throw SyscallException{__FILE__, __LINE__, "setuid failed", errno};
}
}
#endif
oneOfDone = true;
}

Expand Down Expand Up @@ -1105,7 +1066,7 @@ IceInternal::Instance::initialize(const Ice::CommunicatorPtr& communicator)
const_cast<TraceLevelsPtr&>(_traceLevels) = make_shared<TraceLevels>(_initData.properties);

const_cast<DefaultsAndOverridesPtr&>(_defaultsAndOverrides) =
make_shared<DefaultsAndOverrides>(_initData.properties, _initData.logger);
make_shared<DefaultsAndOverrides>(_initData.properties);

const_cast<ConnectionOptions&>(_clientConnectionOptions) = readConnectionOptions("Ice.Connection.Client");
const_cast<ConnectionOptions&>(_serverConnectionOptions) = readConnectionOptions("Ice.Connection.Server");
Expand Down
25 changes: 14 additions & 11 deletions cpp/src/Ice/LocatorInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,12 @@ IceInternal::LocatorTable::clear()
}

bool
IceInternal::LocatorTable::getAdapterEndpoints(const string& adapter, int ttl, vector<EndpointIPtr>& endpoints)
IceInternal::LocatorTable::getAdapterEndpoints(
const string& adapter,
chrono::milliseconds ttl,
vector<EndpointIPtr>& endpoints)
{
if (ttl == 0) // No locator cache.
if (ttl == 0ms) // No locator cache.
{
return false;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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),
Expand All @@ -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<RequestCallback>(ref, ttl, cb);
Expand Down Expand Up @@ -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());
Expand Down
Loading

0 comments on commit 1ae33ad

Please sign in to comment.