Changed non-reentrant network functions to be reentrant and

thread safe.
This commit is contained in:
crs
2002-10-17 20:56:28 +00:00
parent 11e29ff7eb
commit 586a5a81ab
3 changed files with 475 additions and 71 deletions

View File

@@ -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));
}