refactor: Construct std::string outside critical section
There's no need to hold the mutex while constructing a `std::string` from the `char` string. Also use `inet_ntop` instead of the potentially thread-unsafe `inet_ntoa` that might use a static buffer for the result. This makes the `INet` case match the `INet6` case below.
This commit is contained in:
parent
b788d63044
commit
f98f8b10d1
1 changed files with 6 additions and 3 deletions
|
|
@ -590,10 +590,13 @@ std::string ArchNetworkBSD::addrToString(ArchNetAddress addr)
|
||||||
|
|
||||||
switch (getAddrFamily(addr)) {
|
switch (getAddrFamily(addr)) {
|
||||||
case INet: {
|
case INet: {
|
||||||
|
char strAddr[INET_ADDRSTRLEN];
|
||||||
const auto *ipAddr = TYPED_ADDR(struct sockaddr_in, addr);
|
const auto *ipAddr = TYPED_ADDR(struct sockaddr_in, addr);
|
||||||
std::scoped_lock lock{m_mutex};
|
{
|
||||||
std::string s = inet_ntoa(ipAddr->sin_addr);
|
std::scoped_lock lock{m_mutex};
|
||||||
return s;
|
inet_ntop(AF_INET, &ipAddr->sin_addr, strAddr, INET_ADDRSTRLEN);
|
||||||
|
}
|
||||||
|
return strAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
case INet6: {
|
case INet6: {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue