Thread overview |
---|
March 18, 2007 small bugfix for std.socket; use reentrant gethostbyname | ||||
---|---|---|---|---|
| ||||
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 |
March 18, 2007 Re: small bugfix for std.socket; use reentrant gethostbyname | ||||
---|---|---|---|---|
| ||||
Posted in reply to Downs | 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 --downs
Hold on a sec, it looks like mingw has no reentrant gethostbyname_r ... argh x_x
|
March 18, 2007 Re: small bugfix for std.socket; use reentrant gethostbyname | ||||
---|---|---|---|---|
| ||||
Posted in reply to Downs | <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 |
March 18, 2007 Re: small bugfix for std.socket; use reentrant gethostbyname | ||||
---|---|---|---|---|
| ||||
Posted in reply to Downs | 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
|
Copyright © 1999-2021 by the D Language Foundation