[Issue 1478] Please use threadsafe functions in getHostByName

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Oct 13 18:06:22 PDT 2007


http://d.puremagic.com/issues/show_bug.cgi?id=1478


braddr at puremagic.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED




------- Comment #1 from braddr at puremagic.com  2007-10-13 20:06 -------
Given that the _r versions of the functions are glibc specific, I'm much more
inclined to synchronize the call.

Additonally, this only protects one of the several non-threadsafe networking
info api's.

Comitted this diff:

$ svn diff std/socket.d 
Index: std/socket.d
===================================================================
--- std/socket.d        (revision 358)
+++ std/socket.d        (working copy)
@@ -453,7 +453,8 @@
         */     
        bool getHostByName(string name)
        {
-               hostent* he = gethostbyname(toStringz(name));
+               hostent* he;
+                synchronized he = gethostbyname(toStringz(name));
                if(!he)
                        return false;
                validHostent(he);
@@ -468,7 +469,8 @@
        bool getHostByAddr(uint addr)
        {
                uint x = htonl(addr);
-               hostent* he = gethostbyaddr(&x, 4,
cast(int)AddressFamily.INET);
+               hostent* he;
+                synchronized he = gethostbyaddr(&x, 4,
cast(int)AddressFamily.INET);
                if(!he)
                        return false;
                validHostent(he);
@@ -485,7 +487,8 @@
        bool getHostByAddr(string addr)
        {
                uint x = inet_addr(std.string.toStringz(addr));
-               hostent* he = gethostbyaddr(&x, 4,
cast(int)AddressFamily.INET);
+               hostent* he;
+                synchronized he = gethostbyaddr(&x, 4,
cast(int)AddressFamily.INET);
                if(!he)
                        return false;
                validHostent(he);


-- 



More information about the Digitalmars-d-bugs mailing list