D.gnu - small bugfix for std.socket; use reentrant gethostbyname
- Downs (13/17) Mar 18 2007 483,485c485,489
483,485c485,489
< hostent* he = gethostbyname(toStringz(name));
< if(!he)
< return false;
---
hostent he_buf;
char[4096] buffer; int error;
hostent *he;
if (gethostbyname_r(toStringz(name), &he_dump, buffer.ptr,
buffer.length, &he, &error)!=0) return false;
Also, the old way would cause a problem .. because as the manpage for
gethostbyname will verify, if he != 0 doesn't mean there's no error ..
that's what h_errno is for. A return value of 0 from gethostbyname_r,
however, does guarantee there's no error.
(The problem with the return value would cause an error later on,
where populate had to work with an invalid struct - that's how I
found it in the first place)
Greetings --downs
Mar 18 2007
Downs schrieb:483,485c485,489 < hostent* he = gethostbyname(toStringz(name)); < if(!he) < return false; --- > hostent he_buf; > char[4096] buffer; int error; > hostent *he; > if (gethostbyname_r(toStringz(name), &he_dump, buffer.ptr, buffer.length, &he, &error)!=0) return false; Also, the old way would cause a problem .. because as the manpage for gethostbyname will verify, if he != 0 doesn't mean there's no error .. that's what h_errno is for. A return value of 0 from gethostbyname_r, however, does guarantee there's no error. (The problem with the return value would cause an error later on, where populate had to work with an invalid struct - that's how I found it in the first place) Greetings --downsHold on a sec, it looks like mingw has no reentrant gethostbyname_r ... argh x_x
Mar 18 2007
<snip some false information>
Looks like I have to apologize. From the manpage:
The gethostbyname() and gethostbyaddr() functions return the hostent
structure or a NULL pointer if an error occurs. On error, the h_errno
But that is extremely odd, since I have a verified case
where gethostbyname would return a struct with an
_invalid_ h_aliases entry. Confusing.
Perhaps a threading issue? Should gethostbyname usage
be synchronized? I'll look into that.
apologetic --downs
Mar 18 2007
Downs schrieb:
<snip some false information>
Looks like I have to apologize. From the manpage:
> The gethostbyname() and gethostbyaddr() functions return the
hostent
> structure or a NULL pointer if an error occurs. On error, the
h_errno
But that is extremely odd, since I have a verified case
where gethostbyname would return a struct with an
_invalid_ h_aliases entry. Confusing.
Perhaps a threading issue? Should gethostbyname usage
be synchronized? I'll look into that.
apologetic --downs
Yup, wrapping the gethostbyname function in a synchronized
block seems to fix this for me. Any reason not to do that?
--downs
Mar 18 2007








Downs <default_357-line yahoo.de>