Skip to content

Commit 8235f8c

Browse files
committed
Minor fixes in TCP Disconnect.
Use the member PeerAddress in the ActiveConnection object to compare with the passed PeerAddress instead of calling GetPeerInfo() from TCPEndPoint. Log the connection closure in the CloseConnectionInternal function which is also called by CloseActiveConnections() from the TCPBase destructor.
1 parent 4672e1a commit 8235f8c

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

src/transport/raw/TCP.cpp

+6-21
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,10 @@ void TCPBase::CloseConnectionInternal(ActiveTCPConnectionState * connection, CHI
398398

399399
if (connection->mConnectionState != TCPState::kClosed && connection->mEndPoint)
400400
{
401+
char addrStr[Transport::PeerAddress::kMaxToStringSize];
402+
connection->mPeerAddr.ToString(addrStr);
403+
ChipLogProgress(Inet, "Closing connection with peer %s.", addrStr);
404+
401405
if (err == CHIP_NO_ERROR)
402406
{
403407
connection->mEndPoint->Close();
@@ -616,36 +620,17 @@ CHIP_ERROR TCPBase::TCPConnect(const PeerAddress & address, Transport::AppTCPCon
616620

617621
void TCPBase::TCPDisconnect(const PeerAddress & address)
618622
{
619-
CHIP_ERROR err = CHIP_NO_ERROR;
620623
// Closes an existing connection
621624
for (size_t i = 0; i < mActiveConnectionsSize; i++)
622625
{
623626
if (mActiveConnections[i].IsConnected())
624627
{
625-
Inet::IPAddress ipAddress;
626-
uint16_t port;
627-
Inet::InterfaceId interfaceId;
628+
const Inet::IPAddress & ipAddress = mActiveConnections[i].mPeerAddr.GetIPAddress();
629+
uint16_t port = mActiveConnections[i].mPeerAddr.GetPort();
628630

629-
err = mActiveConnections[i].mEndPoint->GetPeerInfo(&ipAddress, &port);
630-
if (err != CHIP_NO_ERROR)
631-
{
632-
ChipLogError(Inet, "TCPDisconnect: GetPeerInfo error: %" CHIP_ERROR_FORMAT, err.Format());
633-
return;
634-
}
635-
636-
err = mActiveConnections[i].mEndPoint->GetInterfaceId(&interfaceId);
637-
if (err != CHIP_NO_ERROR)
638-
{
639-
ChipLogError(Inet, "TCPDisconnect: GetInterfaceId error: %" CHIP_ERROR_FORMAT, err.Format());
640-
return;
641-
}
642631
// if (address == PeerAddress::TCP(ipAddress, port, interfaceId))
643632
if (ipAddress == address.GetIPAddress() && port == address.GetPort())
644633
{
645-
char addrStr[Transport::PeerAddress::kMaxToStringSize];
646-
address.ToString(addrStr);
647-
ChipLogProgress(Inet, "Disconnecting with peer %s.", addrStr);
648-
649634
// NOTE: this leaves the socket in TIME_WAIT.
650635
// Calling Abort() would clean it since SO_LINGER would be set to 0,
651636
// however this seems not to be useful.

0 commit comments

Comments
 (0)