From 9dfebb94bb9bbc1446bdb93019d84cab2deeed67 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Fri, 22 Nov 2024 11:53:15 -0500 Subject: [PATCH] Fix C++ --- cpp/src/Ice/EndpointI.h | 6 ++++-- cpp/src/Ice/IPEndpointI.cpp | 6 ------ cpp/src/Ice/IPEndpointI.h | 1 - cpp/src/Ice/ObjectAdapterI.cpp | 27 ++++++++++++--------------- cpp/src/Ice/OpaqueEndpointI.cpp | 2 +- cpp/src/Ice/OpaqueEndpointI.h | 2 +- cpp/src/Ice/SSL/SSLEndpointI.cpp | 4 ++-- cpp/src/Ice/SSL/SSLEndpointI.h | 2 +- cpp/src/Ice/TcpEndpointI.cpp | 20 ++++++++++++++++++++ cpp/src/Ice/TcpEndpointI.h | 2 ++ cpp/src/Ice/UdpEndpointI.cpp | 15 +++++++++++++++ cpp/src/Ice/UdpEndpointI.h | 2 ++ cpp/src/Ice/WSEndpoint.cpp | 4 ++-- cpp/src/Ice/WSEndpoint.h | 2 +- cpp/src/Ice/ios/iAPEndpointI.h | 2 +- cpp/src/Ice/ios/iAPEndpointI.mm | 2 +- cpp/src/IceBT/EndpointI.cpp | 2 +- cpp/src/IceBT/EndpointI.h | 2 +- cpp/test/Ice/background/EndpointI.cpp | 4 ++-- cpp/test/Ice/background/EndpointI.h | 2 +- cpp/test/Ice/info/AllTests.cpp | 7 +++++-- 21 files changed, 75 insertions(+), 41 deletions(-) diff --git a/cpp/src/Ice/EndpointI.h b/cpp/src/Ice/EndpointI.h index b36a2550c2c..1ca08ca2cb1 100644 --- a/cpp/src/Ice/EndpointI.h +++ b/cpp/src/Ice/EndpointI.h @@ -119,8 +119,10 @@ namespace IceInternal // Returns true when the most underlying endpoint is an IP endpoint with a loopback or multicast address. virtual bool isLoopbackOrMulticast() const = 0; - // Returns a new endpoint with the specified host; returns this when this operation is not applicable. - virtual std::shared_ptr withPublishedHost(std::string host) const = 0; + // Returns a new endpoint with the specified host (if not empty) and all local options cleared. May return + // shared_from_this(). + virtual std::shared_ptr toPublishedEndpoint(std::string publishedHost) const = 0; + // // Check whether the endpoint is equivalent to another one. // diff --git a/cpp/src/Ice/IPEndpointI.cpp b/cpp/src/Ice/IPEndpointI.cpp index 69ec95d7881..29333d5e4ab 100644 --- a/cpp/src/Ice/IPEndpointI.cpp +++ b/cpp/src/Ice/IPEndpointI.cpp @@ -142,12 +142,6 @@ IceInternal::IPEndpointI::isLoopbackOrMulticast() const return _host.empty() ? false : isLoopbackOrMulticastAddress(_host); } -shared_ptr -IceInternal::IPEndpointI::withPublishedHost(string host) const -{ - return createEndpoint(host, _port, _connectionId); -} - bool IceInternal::IPEndpointI::equivalent(const EndpointIPtr& endpoint) const { diff --git a/cpp/src/Ice/IPEndpointI.h b/cpp/src/Ice/IPEndpointI.h index 84ccc0c44d0..5522884e861 100644 --- a/cpp/src/Ice/IPEndpointI.h +++ b/cpp/src/Ice/IPEndpointI.h @@ -50,7 +50,6 @@ namespace IceInternal std::function) const override; std::vector expandHost() const override; bool isLoopbackOrMulticast() const override; - std::shared_ptr withPublishedHost(std::string host) const override; bool equivalent(const EndpointIPtr&) const override; std::size_t hash() const noexcept override; std::string options() const override; diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp index e8805a4c2e1..740cd0f064f 100644 --- a/cpp/src/Ice/ObjectAdapterI.cpp +++ b/cpp/src/Ice/ObjectAdapterI.cpp @@ -1214,25 +1214,22 @@ ObjectAdapterI::computePublishedEndpoints() } // else keep endpoints as-is; they are all loopback or multicast - if (!publishedHost.empty()) - { - vector newEndpoints; + vector newEndpoints; - // Replace the host in all endpoints by publishedHost (when applicable), and remove duplicates. - for (const auto& endpoint : endpoints) + // Replace the host in all endpoints by publishedHost (when applicable), clear local options and remove + // duplicates. + for (const auto& endpoint : endpoints) + { + EndpointIPtr newEndpoint = endpoint->toPublishedEndpoint(publishedHost); + if (find_if( + newEndpoints.begin(), + newEndpoints.end(), + [&newEndpoint](const EndpointIPtr& p) { return *newEndpoint == *p; }) == newEndpoints.end()) { - EndpointIPtr newEndpoint = endpoint->withPublishedHost(publishedHost); - if (find_if( - newEndpoints.begin(), - newEndpoints.end(), - [&newEndpoint](const EndpointIPtr& p) { return *newEndpoint == *p; }) == newEndpoints.end()) - { - newEndpoints.push_back(newEndpoint); - } + newEndpoints.push_back(newEndpoint); } - endpoints = std::move(newEndpoints); } - // else keep the loopback/multicast endpoints as-is (with IP addresses) + endpoints = std::move(newEndpoints); } } diff --git a/cpp/src/Ice/OpaqueEndpointI.cpp b/cpp/src/Ice/OpaqueEndpointI.cpp index cfa14ad543a..1dab41dc724 100644 --- a/cpp/src/Ice/OpaqueEndpointI.cpp +++ b/cpp/src/Ice/OpaqueEndpointI.cpp @@ -175,7 +175,7 @@ IceInternal::OpaqueEndpointI::isLoopbackOrMulticast() const } shared_ptr -IceInternal::OpaqueEndpointI::withPublishedHost(string) const +IceInternal::OpaqueEndpointI::toPublishedEndpoint(string) const { return const_cast(this)->shared_from_this(); } diff --git a/cpp/src/Ice/OpaqueEndpointI.h b/cpp/src/Ice/OpaqueEndpointI.h index 46c008ee9aa..bfdea04dd96 100644 --- a/cpp/src/Ice/OpaqueEndpointI.h +++ b/cpp/src/Ice/OpaqueEndpointI.h @@ -42,7 +42,7 @@ namespace IceInternal acceptor(const std::string&, const std::optional&) const final; std::vector expandHost() const final; bool isLoopbackOrMulticast() const final; - std::shared_ptr withPublishedHost(std::string host) const final; + std::shared_ptr toPublishedEndpoint(std::string publishedHost) const final; bool equivalent(const EndpointIPtr&) const final; std::size_t hash() const noexcept final; std::string options() const final; diff --git a/cpp/src/Ice/SSL/SSLEndpointI.cpp b/cpp/src/Ice/SSL/SSLEndpointI.cpp index fe121054edd..1ecdce33030 100644 --- a/cpp/src/Ice/SSL/SSLEndpointI.cpp +++ b/cpp/src/Ice/SSL/SSLEndpointI.cpp @@ -260,9 +260,9 @@ Ice::SSL::EndpointI::isLoopbackOrMulticast() const } shared_ptr -Ice::SSL::EndpointI::withPublishedHost(string host) const +Ice::SSL::EndpointI::toPublishedEndpoint(string publishedHost) const { - return endpoint(_delegate->withPublishedHost(std::move(host))); + return endpoint(_delegate->toPublishedEndpoint(std::move(publishedHost))); } bool diff --git a/cpp/src/Ice/SSL/SSLEndpointI.h b/cpp/src/Ice/SSL/SSLEndpointI.h index eb03ae7c920..f954d966a38 100644 --- a/cpp/src/Ice/SSL/SSLEndpointI.h +++ b/cpp/src/Ice/SSL/SSLEndpointI.h @@ -44,7 +44,7 @@ namespace Ice::SSL acceptor(const std::string&, const std::optional&) const final; std::vector expandHost() const final; bool isLoopbackOrMulticast() const final; - std::shared_ptr withPublishedHost(std::string host) const final; + std::shared_ptr toPublishedEndpoint(std::string publishedHost) const final; bool equivalent(const IceInternal::EndpointIPtr&) const final; std::size_t hash() const noexcept final; std::string options() const final; diff --git a/cpp/src/Ice/TcpEndpointI.cpp b/cpp/src/Ice/TcpEndpointI.cpp index dceeade014c..bf7897f9f8b 100644 --- a/cpp/src/Ice/TcpEndpointI.cpp +++ b/cpp/src/Ice/TcpEndpointI.cpp @@ -122,6 +122,26 @@ IceInternal::TcpEndpointI::datagram() const return false; } +shared_ptr +IceInternal::TcpEndpointI::toPublishedEndpoint(string publishedHost) const +{ + if (publishedHost.empty() && !isAddressValid(_sourceAddr) && _connectionId.empty()) + { + return const_cast(this)->shared_from_this(); + } + else + { + return make_shared( + _instance, + publishedHost.empty() ? _host : publishedHost, + _port, + Address{}, + _timeout, + "", + _compress); + } +} + TransceiverPtr IceInternal::TcpEndpointI::transceiver() const { diff --git a/cpp/src/Ice/TcpEndpointI.h b/cpp/src/Ice/TcpEndpointI.h index 705dc27bc33..ee65991d143 100644 --- a/cpp/src/Ice/TcpEndpointI.h +++ b/cpp/src/Ice/TcpEndpointI.h @@ -37,6 +37,8 @@ namespace IceInternal EndpointIPtr compress(bool) const final; bool datagram() const final; + std::shared_ptr toPublishedEndpoint(std::string publishedHost) const final; + TransceiverPtr transceiver() const final; AcceptorPtr acceptor(const std::string&, const std::optional&) const final; diff --git a/cpp/src/Ice/UdpEndpointI.cpp b/cpp/src/Ice/UdpEndpointI.cpp index 325d30c67a8..f7e6db54524 100644 --- a/cpp/src/Ice/UdpEndpointI.cpp +++ b/cpp/src/Ice/UdpEndpointI.cpp @@ -149,6 +149,21 @@ IceInternal::UdpEndpointI::datagram() const return true; } +shared_ptr +IceInternal::UdpEndpointI::toPublishedEndpoint(string publishedHost) const +{ + return make_shared( + _instance, + publishedHost.empty() ? _host : publishedHost, + _port, + Address{}, + "", + -1, + false, // for "connect" + "", + _compress); +} + TransceiverPtr IceInternal::UdpEndpointI::transceiver() const { diff --git a/cpp/src/Ice/UdpEndpointI.h b/cpp/src/Ice/UdpEndpointI.h index 6ed878787bf..ac5454719f3 100644 --- a/cpp/src/Ice/UdpEndpointI.h +++ b/cpp/src/Ice/UdpEndpointI.h @@ -41,6 +41,8 @@ namespace IceInternal EndpointIPtr compress(bool) const final; bool datagram() const final; + std::shared_ptr toPublishedEndpoint(std::string publishedHost) const final; + TransceiverPtr transceiver() const final; AcceptorPtr acceptor(const std::string&, const std::optional&) const final; diff --git a/cpp/src/Ice/WSEndpoint.cpp b/cpp/src/Ice/WSEndpoint.cpp index 24fd77a7b7e..af7e0e85276 100644 --- a/cpp/src/Ice/WSEndpoint.cpp +++ b/cpp/src/Ice/WSEndpoint.cpp @@ -281,9 +281,9 @@ IceInternal::WSEndpoint::isLoopbackOrMulticast() const } shared_ptr -IceInternal::WSEndpoint::withPublishedHost(string host) const +IceInternal::WSEndpoint::toPublishedEndpoint(string publishedHost) const { - return endpoint(_delegate->withPublishedHost(std::move(host))); + return endpoint(_delegate->toPublishedEndpoint(std::move(publishedHost))); } bool diff --git a/cpp/src/Ice/WSEndpoint.h b/cpp/src/Ice/WSEndpoint.h index 2dd0d055bb9..69485e656cf 100644 --- a/cpp/src/Ice/WSEndpoint.h +++ b/cpp/src/Ice/WSEndpoint.h @@ -48,7 +48,7 @@ namespace IceInternal acceptor(const std::string&, const std::optional&) const final; std::vector expandHost() const final; bool isLoopbackOrMulticast() const final; - std::shared_ptr withPublishedHost(std::string host) const final; + std::shared_ptr toPublishedEndpoint(std::string publishedHost) const final; bool equivalent(const EndpointIPtr&) const final; std::size_t hash() const noexcept final; std::string options() const final; diff --git a/cpp/src/Ice/ios/iAPEndpointI.h b/cpp/src/Ice/ios/iAPEndpointI.h index 1443a3bd4ef..b417c05c149 100644 --- a/cpp/src/Ice/ios/iAPEndpointI.h +++ b/cpp/src/Ice/ios/iAPEndpointI.h @@ -56,7 +56,7 @@ namespace IceObjC acceptor(const std::string&, const std::optional&) const final; std::vector expandHost() const final; bool isLoopbackOrMulticast() const final; - std::shared_ptr withPublishedHost(std::string host) const final; + std::shared_ptr toPublishedEndpoint(std::string publishedHost) const final; bool equivalent(const IceInternal::EndpointIPtr&) const final; bool operator==(const Ice::Endpoint&) const final; diff --git a/cpp/src/Ice/ios/iAPEndpointI.mm b/cpp/src/Ice/ios/iAPEndpointI.mm index 15c9acd61af..41eb028ec99 100644 --- a/cpp/src/Ice/ios/iAPEndpointI.mm +++ b/cpp/src/Ice/ios/iAPEndpointI.mm @@ -315,7 +315,7 @@ ICEIAP_API void registerIceIAP(bool loadOnInitialize) } shared_ptr -IceObjC::iAPEndpointI::withPublishedHost(string) const +IceObjC::iAPEndpointI::toPublishedEndpoint(string) const { return const_cast(this)->shared_from_this(); } diff --git a/cpp/src/IceBT/EndpointI.cpp b/cpp/src/IceBT/EndpointI.cpp index 31a51ba1336..4dafb2640a3 100644 --- a/cpp/src/IceBT/EndpointI.cpp +++ b/cpp/src/IceBT/EndpointI.cpp @@ -204,7 +204,7 @@ IceBT::EndpointI::isLoopbackOrMulticast() const } shared_ptr -IceBT::EndpointI::withPublishedHost(string) const +IceBT::EndpointI::toPublishedEndpoint(string) const { return const_cast(this)->shared_from_this(); } diff --git a/cpp/src/IceBT/EndpointI.h b/cpp/src/IceBT/EndpointI.h index be8f5c9f64d..5a94aa11f63 100644 --- a/cpp/src/IceBT/EndpointI.h +++ b/cpp/src/IceBT/EndpointI.h @@ -49,7 +49,7 @@ namespace IceBT acceptor(const std::string&, const std::optional&) const final; std::vector expandHost() const final; bool isLoopbackOrMulticast() const final; - std::shared_ptr withPublishedHost(std::string host) const final; + std::shared_ptr toPublishedEndpoint(std::string publishedHost) const final; bool equivalent(const IceInternal::EndpointIPtr&) const final; bool operator==(const Ice::Endpoint&) const final; diff --git a/cpp/test/Ice/background/EndpointI.cpp b/cpp/test/Ice/background/EndpointI.cpp index b7ed2a78a70..f339589f25d 100644 --- a/cpp/test/Ice/background/EndpointI.cpp +++ b/cpp/test/Ice/background/EndpointI.cpp @@ -206,9 +206,9 @@ EndpointI::isLoopbackOrMulticast() const } shared_ptr -EndpointI::withPublishedHost(string host) const +EndpointI::toPublishedEndpoint(string publishedHost) const { - return endpoint(_endpoint->withPublishedHost(std::move(host))); + return endpoint(_endpoint->toPublishedEndpoint(std::move(publishedHost))); } bool diff --git a/cpp/test/Ice/background/EndpointI.h b/cpp/test/Ice/background/EndpointI.h index 300f025c1c8..41bd61b0c13 100644 --- a/cpp/test/Ice/background/EndpointI.h +++ b/cpp/test/Ice/background/EndpointI.h @@ -36,7 +36,7 @@ class EndpointI final : public IceInternal::EndpointI, public std::enable_shared acceptor(const std::string&, const std::optional&) const final; std::vector expandHost() const final; bool isLoopbackOrMulticast() const final; - std::shared_ptr withPublishedHost(std::string host) const final; + std::shared_ptr toPublishedEndpoint(std::string publishedHost) const final; bool equivalent(const IceInternal::EndpointIPtr&) const final; // From TestEndpoint diff --git a/cpp/test/Ice/info/AllTests.cpp b/cpp/test/Ice/info/AllTests.cpp index dcc61f52245..87cd0e2997b 100644 --- a/cpp/test/Ice/info/AllTests.cpp +++ b/cpp/test/Ice/info/AllTests.cpp @@ -109,7 +109,9 @@ allTests(Test::TestHelper* helper) Ice::EndpointSeq endpoints = adapter->getEndpoints(); test(endpoints.size() == 2); Ice::EndpointSeq publishedEndpoints = adapter->getPublishedEndpoints(); - test(endpoints == publishedEndpoints); + test(publishedEndpoints.size() == 2); + test(*endpoints[0] == *publishedEndpoints[0]); + test(*endpoints[1] == *publishedEndpoints[1]); Ice::TCPEndpointInfoPtr ipEndpoint = getTCPEndpointInfo(endpoints[0]->getInfo()); test(ipEndpoint); @@ -130,7 +132,8 @@ allTests(Test::TestHelper* helper) test(endpoints.size() == 1); adapter->setPublishedEndpoints(endpoints); publishedEndpoints = adapter->getPublishedEndpoints(); - test(endpoints == publishedEndpoints); + test(publishedEndpoints.size() == 1); + test(*endpoints[0] == *publishedEndpoints[0]); adapter->destroy();