[Issue 1478] New: Please use threadsafe functions in getHostByName

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Sep 6 05:48:03 PDT 2007


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

           Summary: Please use threadsafe functions in getHostByName
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: default_357-line at yahoo.de


The following patch will change socket.d to use threadsafe functions for the
gethostbyname call on non-windows platforms. Not doing this can lead to all
sorts of ugly problems when using sockets in multi-threaded programs.
The patch is originally for gdc's socket.d, but should be equally applicable to
DMD.

diff socket.d.broken socket.d
487c487,497
<               hostent* he = gethostbyname(toStringz(name));
---
>               version (Windows)
>                       hostent* he = gethostbyname(toStringz(name));
>               else
>               {
>                       auto he = new hostent;
>                       auto buffer=new char[512];
>                       int errno;
>                       getHostByName_retry: // if we had extended do { } while { } this would not be necessary.
>                       auto res = gethostbyname_r(toStringz(name), he, buffer.ptr, buffer.length, &he, &errno);
>                       if (res == ERANGE) { buffer.length = buffer.length * 2; if (!he) he=new hostent; goto getHostByName_retry; }
>               }


-- 



More information about the Digitalmars-d-bugs mailing list