Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes in TCP Disconnect. #34142

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 12 additions & 24 deletions src/transport/raw/TCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,10 @@ void TCPBase::CloseConnectionInternal(ActiveTCPConnectionState * connection, CHI

if (connection->mConnectionState != TCPState::kClosed && connection->mEndPoint)
{
char addrStr[Transport::PeerAddress::kMaxToStringSize];
connection->mPeerAddr.ToString(addrStr);
ChipLogProgress(Inet, "Closing connection with peer %s.", addrStr);

if (err == CHIP_NO_ERROR)
{
connection->mEndPoint->Close();
Expand Down Expand Up @@ -616,36 +620,20 @@ CHIP_ERROR TCPBase::TCPConnect(const PeerAddress & address, Transport::AppTCPCon

void TCPBase::TCPDisconnect(const PeerAddress & address)
{
CHIP_ERROR err = CHIP_NO_ERROR;
// Closes an existing connection
for (size_t i = 0; i < mActiveConnectionsSize; i++)
{
if (mActiveConnections[i].IsConnected())
{
Inet::IPAddress ipAddress;
uint16_t port;
Inet::InterfaceId interfaceId;

err = mActiveConnections[i].mEndPoint->GetPeerInfo(&ipAddress, &port);
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
if (err != CHIP_NO_ERROR)
{
ChipLogError(Inet, "TCPDisconnect: GetPeerInfo error: %" CHIP_ERROR_FORMAT, err.Format());
return;
}

err = mActiveConnections[i].mEndPoint->GetInterfaceId(&interfaceId);
if (err != CHIP_NO_ERROR)
const Inet::IPAddress & ipAddress = mActiveConnections[i].mPeerAddr.GetIPAddress();
uint16_t port = mActiveConnections[i].mPeerAddr.GetPort();

// Ignoring the InterfaceID in the check as it may not have been provided in
// the PeerAddress during connection establishment. The IPAddress and Port
// are the necessary and sufficient set of parameters for searching
// through the connections.
if (ipAddress == address.GetIPAddress() && port == address.GetPort() && address.GetTransportType() == Type::kTcp)
{
ChipLogError(Inet, "TCPDisconnect: GetInterfaceId error: %" CHIP_ERROR_FORMAT, err.Format());
return;
}
// if (address == PeerAddress::TCP(ipAddress, port, interfaceId))
if (ipAddress == address.GetIPAddress() && port == address.GetPort())
{
char addrStr[Transport::PeerAddress::kMaxToStringSize];
address.ToString(addrStr);
ChipLogProgress(Inet, "Disconnecting with peer %s.", addrStr);

// NOTE: this leaves the socket in TIME_WAIT.
// Calling Abort() would clean it since SO_LINGER would be set to 0,
// however this seems not to be useful.
Expand Down
Loading