Skip to content

Commit

Permalink
Fix C++
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier committed Nov 22, 2024
1 parent 3513e47 commit 9dfebb9
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 41 deletions.
6 changes: 4 additions & 2 deletions cpp/src/Ice/EndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<EndpointI> 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<EndpointI> toPublishedEndpoint(std::string publishedHost) const = 0;

//
// Check whether the endpoint is equivalent to another one.
//
Expand Down
6 changes: 0 additions & 6 deletions cpp/src/Ice/IPEndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,6 @@ IceInternal::IPEndpointI::isLoopbackOrMulticast() const
return _host.empty() ? false : isLoopbackOrMulticastAddress(_host);
}

shared_ptr<EndpointI>
IceInternal::IPEndpointI::withPublishedHost(string host) const
{
return createEndpoint(host, _port, _connectionId);
}

bool
IceInternal::IPEndpointI::equivalent(const EndpointIPtr& endpoint) const
{
Expand Down
1 change: 0 additions & 1 deletion cpp/src/Ice/IPEndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ namespace IceInternal
std::function<void(std::exception_ptr)>) const override;
std::vector<EndpointIPtr> expandHost() const override;
bool isLoopbackOrMulticast() const override;
std::shared_ptr<EndpointI> withPublishedHost(std::string host) const override;
bool equivalent(const EndpointIPtr&) const override;
std::size_t hash() const noexcept override;
std::string options() const override;
Expand Down
27 changes: 12 additions & 15 deletions cpp/src/Ice/ObjectAdapterI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1214,25 +1214,22 @@ ObjectAdapterI::computePublishedEndpoints()
}
// else keep endpoints as-is; they are all loopback or multicast

if (!publishedHost.empty())
{
vector<EndpointIPtr> newEndpoints;
vector<EndpointIPtr> 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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/OpaqueEndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ IceInternal::OpaqueEndpointI::isLoopbackOrMulticast() const
}

shared_ptr<EndpointI>
IceInternal::OpaqueEndpointI::withPublishedHost(string) const
IceInternal::OpaqueEndpointI::toPublishedEndpoint(string) const
{
return const_cast<OpaqueEndpointI*>(this)->shared_from_this();
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/OpaqueEndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace IceInternal
acceptor(const std::string&, const std::optional<Ice::SSL::ServerAuthenticationOptions>&) const final;
std::vector<EndpointIPtr> expandHost() const final;
bool isLoopbackOrMulticast() const final;
std::shared_ptr<EndpointI> withPublishedHost(std::string host) const final;
std::shared_ptr<EndpointI> toPublishedEndpoint(std::string publishedHost) const final;
bool equivalent(const EndpointIPtr&) const final;
std::size_t hash() const noexcept final;
std::string options() const final;
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/Ice/SSL/SSLEndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ Ice::SSL::EndpointI::isLoopbackOrMulticast() const
}

shared_ptr<IceInternal::EndpointI>
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
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/SSL/SSLEndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace Ice::SSL
acceptor(const std::string&, const std::optional<Ice::SSL::ServerAuthenticationOptions>&) const final;
std::vector<IceInternal::EndpointIPtr> expandHost() const final;
bool isLoopbackOrMulticast() const final;
std::shared_ptr<IceInternal::EndpointI> withPublishedHost(std::string host) const final;
std::shared_ptr<IceInternal::EndpointI> 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;
Expand Down
20 changes: 20 additions & 0 deletions cpp/src/Ice/TcpEndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,26 @@ IceInternal::TcpEndpointI::datagram() const
return false;
}

shared_ptr<EndpointI>
IceInternal::TcpEndpointI::toPublishedEndpoint(string publishedHost) const
{
if (publishedHost.empty() && !isAddressValid(_sourceAddr) && _connectionId.empty())
{
return const_cast<TcpEndpointI*>(this)->shared_from_this();
}
else
{
return make_shared<TcpEndpointI>(
_instance,
publishedHost.empty() ? _host : publishedHost,
_port,
Address{},
_timeout,
"",
_compress);
}
}

TransceiverPtr
IceInternal::TcpEndpointI::transceiver() const
{
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/Ice/TcpEndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ namespace IceInternal
EndpointIPtr compress(bool) const final;
bool datagram() const final;

std::shared_ptr<EndpointI> toPublishedEndpoint(std::string publishedHost) const final;

TransceiverPtr transceiver() const final;
AcceptorPtr
acceptor(const std::string&, const std::optional<Ice::SSL::ServerAuthenticationOptions>&) const final;
Expand Down
15 changes: 15 additions & 0 deletions cpp/src/Ice/UdpEndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@ IceInternal::UdpEndpointI::datagram() const
return true;
}

shared_ptr<EndpointI>
IceInternal::UdpEndpointI::toPublishedEndpoint(string publishedHost) const
{
return make_shared<UdpEndpointI>(
_instance,
publishedHost.empty() ? _host : publishedHost,
_port,
Address{},
"",
-1,
false, // for "connect"
"",
_compress);
}

TransceiverPtr
IceInternal::UdpEndpointI::transceiver() const
{
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/Ice/UdpEndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ namespace IceInternal
EndpointIPtr compress(bool) const final;
bool datagram() const final;

std::shared_ptr<EndpointI> toPublishedEndpoint(std::string publishedHost) const final;

TransceiverPtr transceiver() const final;
AcceptorPtr
acceptor(const std::string&, const std::optional<Ice::SSL::ServerAuthenticationOptions>&) const final;
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/Ice/WSEndpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ IceInternal::WSEndpoint::isLoopbackOrMulticast() const
}

shared_ptr<EndpointI>
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
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/WSEndpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace IceInternal
acceptor(const std::string&, const std::optional<Ice::SSL::ServerAuthenticationOptions>&) const final;
std::vector<EndpointIPtr> expandHost() const final;
bool isLoopbackOrMulticast() const final;
std::shared_ptr<EndpointI> withPublishedHost(std::string host) const final;
std::shared_ptr<EndpointI> toPublishedEndpoint(std::string publishedHost) const final;
bool equivalent(const EndpointIPtr&) const final;
std::size_t hash() const noexcept final;
std::string options() const final;
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/ios/iAPEndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace IceObjC
acceptor(const std::string&, const std::optional<Ice::SSL::ServerAuthenticationOptions>&) const final;
std::vector<IceInternal::EndpointIPtr> expandHost() const final;
bool isLoopbackOrMulticast() const final;
std::shared_ptr<EndpointI> withPublishedHost(std::string host) const final;
std::shared_ptr<EndpointI> toPublishedEndpoint(std::string publishedHost) const final;
bool equivalent(const IceInternal::EndpointIPtr&) const final;

bool operator==(const Ice::Endpoint&) const final;
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/ios/iAPEndpointI.mm
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ ICEIAP_API void registerIceIAP(bool loadOnInitialize)
}

shared_ptr<EndpointI>
IceObjC::iAPEndpointI::withPublishedHost(string) const
IceObjC::iAPEndpointI::toPublishedEndpoint(string) const
{
return const_cast<iAPEndpointI*>(this)->shared_from_this();
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/IceBT/EndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ IceBT::EndpointI::isLoopbackOrMulticast() const
}

shared_ptr<IceInternal::EndpointI>
IceBT::EndpointI::withPublishedHost(string) const
IceBT::EndpointI::toPublishedEndpoint(string) const
{
return const_cast<EndpointI*>(this)->shared_from_this();
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/IceBT/EndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace IceBT
acceptor(const std::string&, const std::optional<Ice::SSL::ServerAuthenticationOptions>&) const final;
std::vector<IceInternal::EndpointIPtr> expandHost() const final;
bool isLoopbackOrMulticast() const final;
std::shared_ptr<IceInternal::EndpointI> withPublishedHost(std::string host) const final;
std::shared_ptr<IceInternal::EndpointI> toPublishedEndpoint(std::string publishedHost) const final;
bool equivalent(const IceInternal::EndpointIPtr&) const final;

bool operator==(const Ice::Endpoint&) const final;
Expand Down
4 changes: 2 additions & 2 deletions cpp/test/Ice/background/EndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ EndpointI::isLoopbackOrMulticast() const
}

shared_ptr<IceInternal::EndpointI>
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
Expand Down
2 changes: 1 addition & 1 deletion cpp/test/Ice/background/EndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class EndpointI final : public IceInternal::EndpointI, public std::enable_shared
acceptor(const std::string&, const std::optional<Ice::SSL::ServerAuthenticationOptions>&) const final;
std::vector<IceInternal::EndpointIPtr> expandHost() const final;
bool isLoopbackOrMulticast() const final;
std::shared_ptr<IceInternal::EndpointI> withPublishedHost(std::string host) const final;
std::shared_ptr<IceInternal::EndpointI> toPublishedEndpoint(std::string publishedHost) const final;
bool equivalent(const IceInternal::EndpointIPtr&) const final;

// From TestEndpoint
Expand Down
7 changes: 5 additions & 2 deletions cpp/test/Ice/info/AllTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();

Expand Down

0 comments on commit 9dfebb9

Please sign in to comment.