mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 14:40:30 +03:00
Fixed static destructor so sockets aren't closed on every thread exit in windows. (see bug 4344 and 4951)
Fixed unlisted bug, there could be a race condition on linux with gethostbyname and gethostbyaddr, now synchronizing entire processing of hostent struct.
This commit is contained in:
parent
a3cabfb7e8
commit
6fb30a1b5e
1 changed files with 64 additions and 16 deletions
80
std/socket.d
80
std/socket.d
|
@ -191,7 +191,7 @@ shared static this()
|
|||
}
|
||||
|
||||
|
||||
static ~this()
|
||||
shared static ~this()
|
||||
{
|
||||
version(Win32)
|
||||
{
|
||||
|
@ -535,12 +535,28 @@ class InternetHost
|
|||
*/
|
||||
bool getHostByName(string name)
|
||||
{
|
||||
hostent* he;
|
||||
synchronized(this.classinfo) he = gethostbyname(toStringz(name));
|
||||
if(!he)
|
||||
version(Windows)
|
||||
{
|
||||
// TODO gethostbyname is deprecated in windows, use getaddrinfo
|
||||
auto he = gethostbyname(toStringz(name));
|
||||
if(!he)
|
||||
return false;
|
||||
validHostent(he);
|
||||
populate(he);
|
||||
validHostent(he);
|
||||
populate(he);
|
||||
}
|
||||
else
|
||||
{
|
||||
// posix systems use global state for return value, so we
|
||||
// must synchronize across all threads
|
||||
synchronized(this.classinfo)
|
||||
{
|
||||
auto he = gethostbyname(toStringz(name));
|
||||
if(!he)
|
||||
return false;
|
||||
validHostent(he);
|
||||
populate(he);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -551,12 +567,28 @@ class InternetHost
|
|||
bool getHostByAddr(uint addr)
|
||||
{
|
||||
uint x = htonl(addr);
|
||||
hostent* he;
|
||||
synchronized(this.classinfo) he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET);
|
||||
if(!he)
|
||||
version(Windows)
|
||||
{
|
||||
// TODO gethostbyaddr is deprecated in windows, use getnameinfo
|
||||
auto he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET);
|
||||
if(!he)
|
||||
return false;
|
||||
validHostent(he);
|
||||
populate(he);
|
||||
validHostent(he);
|
||||
populate(he);
|
||||
}
|
||||
else
|
||||
{
|
||||
// posix systems use global state for return value, so we
|
||||
// must synchronize across all threads
|
||||
synchronized(this.classinfo)
|
||||
{
|
||||
auto he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET);
|
||||
if(!he)
|
||||
return false;
|
||||
validHostent(he);
|
||||
populate(he);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -569,12 +601,28 @@ class InternetHost
|
|||
bool getHostByAddr(string addr)
|
||||
{
|
||||
uint x = inet_addr(std.string.toStringz(addr));
|
||||
hostent* he;
|
||||
synchronized(this.classinfo) he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET);
|
||||
if(!he)
|
||||
version(Windows)
|
||||
{
|
||||
// TODO gethostbyaddr is deprecated in windows, use getnameinfo
|
||||
auto he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET);
|
||||
if(!he)
|
||||
return false;
|
||||
validHostent(he);
|
||||
populate(he);
|
||||
validHostent(he);
|
||||
populate(he);
|
||||
}
|
||||
else
|
||||
{
|
||||
// posix systems use global state for return value, so we
|
||||
// must synchronize across all threads
|
||||
synchronized(this.classinfo)
|
||||
{
|
||||
auto he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET);
|
||||
if(!he)
|
||||
return false;
|
||||
validHostent(he);
|
||||
populate(he);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue