Skip to content

Commit

Permalink
Simplify TcpEndpointI
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier committed Nov 22, 2024
1 parent 9dfebb9 commit fd4e695
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 27 deletions.
14 changes: 5 additions & 9 deletions cpp/src/Ice/TcpEndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,16 @@ IceInternal::TcpEndpointI::datagram() const
shared_ptr<EndpointI>
IceInternal::TcpEndpointI::toPublishedEndpoint(string publishedHost) const
{
if (publishedHost.empty() && !isAddressValid(_sourceAddr) && _connectionId.empty())
// A server endpoint can't have a source address or connection ID.
assert(!isAddressValid(_sourceAddr) && _connectionId.empty());

if (publishedHost.empty())
{
return const_cast<TcpEndpointI*>(this)->shared_from_this();
}
else
{
return make_shared<TcpEndpointI>(
_instance,
publishedHost.empty() ? _host : publishedHost,
_port,
Address{},
_timeout,
"",
_compress);
return make_shared<TcpEndpointI>(_instance, publishedHost, _port, Address{}, _timeout, "", _compress);
}
}

Expand Down
14 changes: 5 additions & 9 deletions csharp/src/Ice/Internal/TcpEndpointI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,16 @@ public override void fillEndpointInfo(Ice.IPEndpointInfo info)

public override EndpointI toPublishedEndpoint(string publishedHost)
{
if (publishedHost.Length == 0 && sourceAddr_ is null && connectionId_.Length == 0)
// A server endpoint can't have a source address or connection ID.
Debug.Assert(sourceAddr_ is null && connectionId_.Length == 0);

if (publishedHost.Length == 0)
{
return this;
}
else
{
return new TcpEndpointI(
instance_,
publishedHost.Length > 0 ? publishedHost : host_,
port_,
sourceAddr: null,
_timeout,
conId: "",
_compress);
return new TcpEndpointI(instance_, publishedHost, port_, sourceAddr: null, _timeout, conId: "", _compress);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,12 @@ public int hashCode() {

@Override
public EndpointI toPublishedEndpoint(String publishedHost) {
if (publishedHost.isEmpty() && _sourceAddr == null && _connectionId.isEmpty()) {
// A server endpoint can't have a source address or connection ID.
assert (_sourceAddr == null && _connectionId.isEmpty());
if (publishedHost.isEmpty()) {
return this;
} else {
return new TcpEndpointI(
_instance,
publishedHost.isEmpty() ? _host : publishedHost,
_port,
null,
_timeout,
"",
_compress);
return new TcpEndpointI(_instance, publishedHost, _port, null, _timeout, "", _compress);
}
}

Expand Down

0 comments on commit fd4e695

Please sign in to comment.