Skip to content

Commit

Permalink
Change ConnectionInfo::adapterName
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier committed Nov 26, 2024
1 parent 132f832 commit ef42de8
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cpp/include/Ice/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ namespace Ice
const bool incoming;

/**
* The name of the adapter associated with the connection.
* The name of the object adapter that created this incoming connection.
*/
const std::string adapterName;

Expand Down
10 changes: 6 additions & 4 deletions cpp/src/Ice/ConnectionI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3493,17 +3493,19 @@ Ice::ConnectionI::dispatchAll(
Ice::ConnectionInfoPtr
Ice::ConnectionI::initConnectionInfo() const
{
// Called with _mutex locked.

if (_state > StateNotInitialized && _info) // Update the connection information until it's initialized
{
return _info;
}

bool incoming = !_connector;

// _adapter is set for an incoming connection until "finished"
_info = _transceiver->getInfo(
_connector == nullptr,
_adapter ? _adapter->getName() : string{},
incoming,
incoming && _adapter ? _adapter->getName() : string{},
_endpoint->connectionId());

return _info;
}

Expand Down
18 changes: 17 additions & 1 deletion cpp/src/Ice/SSL/OpenSSLTransceiverI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,23 @@ Ice::ConnectionInfoPtr
OpenSSL::TransceiverI::getInfo(bool incoming, string adapterName, string connectionId) const
{
assert(incoming == _incoming);
assert(adapterName == _adapterName);

if (incoming)
{
// adapterName can be empty during connection shutdown
if (adapterName.empty())
{
adapterName = _adapterName;
}
else
{
assert(adapterName == _adapterName);
}
}
else
{
assert(adapterName.empty());
}

X509* peerCertificate = nullptr;
if (_peerCertificate)
Expand Down
18 changes: 17 additions & 1 deletion cpp/src/Ice/SSL/SchannelTransceiverI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,23 @@ Ice::ConnectionInfoPtr
Schannel::TransceiverI::getInfo(bool incoming, string adapterName, string connectionId) const
{
assert(incoming == _incoming);
assert(adapterName == _adapterName);

if (incoming)
{
// adapterName can be empty during connection shutdown
if (adapterName.empty())
{
adapterName = _adapterName;
}
else
{
assert(adapterName == _adapterName);
}
}
else
{
assert(adapterName.empty());
}

return make_shared<ConnectionInfo>(
_delegate->getInfo(incoming, std::move(adapterName), std::move(connectionId)),
Expand Down
18 changes: 17 additions & 1 deletion cpp/src/Ice/SSL/SecureTransportTransceiverI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,23 @@ Ice::ConnectionInfoPtr
Ice::SSL::SecureTransport::TransceiverI::getInfo(bool incoming, string adapterName, string connectionId) const
{
assert(incoming == _incoming);
assert(adapterName == _adapterName);

if (incoming)
{
// adapterName can be empty during connection shutdown
if (adapterName.empty())
{
adapterName = _adapterName;
}
else
{
assert(adapterName == _adapterName);
}
}
else
{
assert(adapterName.empty());
}

SecCertificateRef peerCertificate = nullptr;

Expand Down
6 changes: 6 additions & 0 deletions cpp/src/Ice/Transceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ namespace IceInternal
virtual std::string toString() const = 0;
virtual std::string toDetailedString() const = 0;

/// @brief Creates a connection info object for this connection.
/// @param incoming true for an incoming connection, false for an outgoing connection.
/// @param adapterName The name of the object adapter that created this connection. It's empty when incoming is
/// false.
/// @param connectionId The connection ID of this connection.
/// @return The new connection info.
virtual Ice::ConnectionInfoPtr
getInfo(bool incoming, std::string adapterName, std::string connectionId) const = 0;

Expand Down
9 changes: 8 additions & 1 deletion csharp/src/Ice/ConnectionI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2667,7 +2667,14 @@ private ConnectionInfo initConnectionInfo()
return _info;
}

_info = _transceiver.getInfo(incoming: _connector is null, _adapter?.getName() ?? "", _endpoint.connectionId());
bool incoming = _connector is null;

// For incoming connections, the adapter is not null until "finished".
_info = _transceiver.getInfo(
incoming,
incoming ? _adapter?.getName() ?? "" : "",
_endpoint.connectionId());

return _info;
}

Expand Down
7 changes: 7 additions & 0 deletions csharp/src/Ice/Internal/Transceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ public interface Transceiver

string toDetailedString();

/// <summary>Creates a connection info object for this connection.</summary>
/// <param name="incoming"><see langword="true"/> for an incoming connection, <see langword="true"/> for an outgoing
/// connection.</param>
/// <param name="adapterName">The name of the object adapter that created this connection. It's empty when
/// <paramref name="incoming"/> is <see langword="false"/>.</param>
/// <param name="connectionId">The connection ID of this connection.</param>
/// <returns>The new connection info.</returns>
ConnectionInfo getInfo(bool incoming, string adapterName, string connectionId);

void checkSendSize(Buffer buf);
Expand Down
16 changes: 15 additions & 1 deletion csharp/src/Ice/SSL/TransceiverI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,21 @@ public void finishWrite(Ice.Internal.Buffer buf)
public Ice.ConnectionInfo getInfo(bool incoming, string adapterName, string connectionId)
{
Debug.Assert(incoming == _incoming);
Debug.Assert(adapterName == _adapterName);
if (incoming)
{
if (adapterName.Length == 0) // cleared during shutdown
{
adapterName = _adapterName;
}
else
{
Debug.Assert(adapterName == _adapterName);
}
}
else
{
Debug.Assert(adapterName.Length == 0);
}

return new Ice.SSL.ConnectionInfo(
_delegate.getInfo(incoming, adapterName, connectionId),
Expand Down

0 comments on commit ef42de8

Please sign in to comment.