Codechange: Swap SocketList map key/value around.

This map is used store socket and address together, and, other than
checking that the address does not already have a socket, the data layout
does not seem particularly important.

However, as address is the key, technically it should not be modified,
and address may self-modify itself during comparisons.
This commit is contained in:
Peter Nelson
2023-05-16 23:53:33 +01:00
committed by PeterN
parent f454ec8d63
commit 72018badff
4 changed files with 12 additions and 12 deletions

View File

@@ -259,7 +259,7 @@ SOCKET NetworkAddress::Resolve(int family, int socktype, int flags, SocketList *
* of course totally unneeded ;) */
if (sockets != nullptr) {
NetworkAddress address(runp->ai_addr, (int)runp->ai_addrlen);
if (sockets->Contains(address)) continue;
if (std::any_of(sockets->begin(), sockets->end(), [&address](const auto &p) { return p.second == address; })) continue;
}
sock = func(runp);
if (sock == INVALID_SOCKET) continue;
@@ -284,7 +284,7 @@ SOCKET NetworkAddress::Resolve(int family, int socktype, int flags, SocketList *
}
NetworkAddress addr(runp->ai_addr, (int)runp->ai_addrlen);
(*sockets)[addr] = sock;
(*sockets)[sock] = addr;
sock = INVALID_SOCKET;
}
freeaddrinfo (ai);