mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 22:50:38 +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
62
std/socket.d
62
std/socket.d
|
@ -191,7 +191,7 @@ shared static this()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static ~this()
|
shared static ~this()
|
||||||
{
|
{
|
||||||
version(Win32)
|
version(Win32)
|
||||||
{
|
{
|
||||||
|
@ -535,12 +535,28 @@ class InternetHost
|
||||||
*/
|
*/
|
||||||
bool getHostByName(string name)
|
bool getHostByName(string name)
|
||||||
{
|
{
|
||||||
hostent* he;
|
version(Windows)
|
||||||
synchronized(this.classinfo) he = gethostbyname(toStringz(name));
|
{
|
||||||
|
// TODO gethostbyname is deprecated in windows, use getaddrinfo
|
||||||
|
auto he = gethostbyname(toStringz(name));
|
||||||
if(!he)
|
if(!he)
|
||||||
return false;
|
return false;
|
||||||
validHostent(he);
|
validHostent(he);
|
||||||
populate(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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -551,12 +567,28 @@ class InternetHost
|
||||||
bool getHostByAddr(uint addr)
|
bool getHostByAddr(uint addr)
|
||||||
{
|
{
|
||||||
uint x = htonl(addr);
|
uint x = htonl(addr);
|
||||||
hostent* he;
|
version(Windows)
|
||||||
synchronized(this.classinfo) he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET);
|
{
|
||||||
|
// TODO gethostbyaddr is deprecated in windows, use getnameinfo
|
||||||
|
auto he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET);
|
||||||
if(!he)
|
if(!he)
|
||||||
return false;
|
return false;
|
||||||
validHostent(he);
|
validHostent(he);
|
||||||
populate(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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -569,12 +601,28 @@ class InternetHost
|
||||||
bool getHostByAddr(string addr)
|
bool getHostByAddr(string addr)
|
||||||
{
|
{
|
||||||
uint x = inet_addr(std.string.toStringz(addr));
|
uint x = inet_addr(std.string.toStringz(addr));
|
||||||
hostent* he;
|
version(Windows)
|
||||||
synchronized(this.classinfo) he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET);
|
{
|
||||||
|
// TODO gethostbyaddr is deprecated in windows, use getnameinfo
|
||||||
|
auto he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET);
|
||||||
if(!he)
|
if(!he)
|
||||||
return false;
|
return false;
|
||||||
validHostent(he);
|
validHostent(he);
|
||||||
populate(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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue