mirror of
https://github.com/debauchee/barrier.git
synced 2026-05-08 14:41:57 +08:00
Changed non-reentrant network functions to be reentrant and
thread safe.
This commit is contained in:
@@ -126,27 +126,29 @@ CNetworkAddress::CNetworkAddress(const CString& hostname_, UInt16 port) :
|
||||
}
|
||||
|
||||
// look up name
|
||||
struct hostent* hent = CNetwork::gethostbyname(hostname.c_str());
|
||||
if (hent == NULL) {
|
||||
switch (CNetwork::gethosterror()) {
|
||||
case CNetwork::kHOST_NOT_FOUND:
|
||||
throw XSocketAddress(XSocketAddress::kNotFound, hostname, port);
|
||||
CNetwork::CHostInfo hostInfo;
|
||||
switch (CNetwork::gethostbyname(&hostInfo, hostname.c_str())) {
|
||||
case CNetwork::kHOST_OK:
|
||||
break;
|
||||
|
||||
case CNetwork::kNO_DATA:
|
||||
throw XSocketAddress(XSocketAddress::kNoAddress, hostname, port);
|
||||
case CNetwork::kHOST_NOT_FOUND:
|
||||
throw XSocketAddress(XSocketAddress::kNotFound, hostname, port);
|
||||
|
||||
case CNetwork::kNO_RECOVERY:
|
||||
case CNetwork::kTRY_AGAIN:
|
||||
default:
|
||||
throw XSocketAddress(XSocketAddress::kUnknown, hostname, port);
|
||||
}
|
||||
case CNetwork::kNO_DATA:
|
||||
throw XSocketAddress(XSocketAddress::kNoAddress, hostname, port);
|
||||
|
||||
case CNetwork::kNO_RECOVERY:
|
||||
case CNetwork::kTRY_AGAIN:
|
||||
default:
|
||||
throw XSocketAddress(XSocketAddress::kUnknown, hostname, port);
|
||||
}
|
||||
|
||||
struct sockaddr_in* inetAddress = reinterpret_cast<
|
||||
struct sockaddr_in*>(&m_address);
|
||||
inetAddress->sin_family = hent->h_addrtype;
|
||||
inetAddress->sin_family = hostInfo.m_addressType;
|
||||
inetAddress->sin_port = CNetwork::swaphtons(port);
|
||||
memcpy(&inetAddress->sin_addr, hent->h_addr_list[0], hent->h_length);
|
||||
memcpy(&inetAddress->sin_addr, hostInfo.m_addresses[0],
|
||||
hostInfo.m_addressLength);
|
||||
memset(inetAddress->sin_zero, 0, sizeof(inetAddress->sin_zero));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user