From: Stephen D. <sd...@gm...> - 2005-04-11 03:05:39
|
I guess this is an OSX problem? While looking at the configure tests, I noticed that gethostbyname_r etc. are not used on Linux, even though they're available. The standard call is thread safe, but only because glibc puts a lock around everything. I wonder if for performance the *_r variants should always be preferred...? On Apr 9, 2005 3:16 AM, Zoran Vasiljevic <vas...@us...> wrote: > Update of /cvsroot/naviserver/naviserver/nsd > In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21706 > > Modified Files: > dns.c > Log Message: > Fixed GetAddr when dealing with gethostbyname_r calls. In some cases > we ended up in an infinite loop. > > Index: dns.c > =================================================================== > RCS file: /cvsroot/naviserver/naviserver/nsd/dns.c,v > retrieving revision 1.1.1.1 > retrieving revision 1.2 > diff -C2 -d -r1.1.1.1 -r1.2 > *** dns.c 16 Feb 2005 08:39:25 -0000 1.1.1.1 > --- dns.c 9 Apr 2005 09:16:15 -0000 1.2 > *************** > *** 1,7 **** > /* > ! * The contents of this file are subject to the AOLserver Public License > * Version 1.1 (the "License"); you may not use this file except in > * compliance with the License. You may obtain a copy of the License at > ! * http://aolserver.com/. > * > * Software distributed under the License is distributed on an "AS IS" > --- 1,7 ---- > /* > ! * The contents of this file are subject to the Mozilla Public License > * Version 1.1 (the "License"); you may not use this file except in > * compliance with the License. You may obtain a copy of the License at > ! * http://mozilla.org/. > * > * Software distributed under the License is distributed on an "AS IS" > *************** > *** 347,354 **** > Tcl_DStringAppendElement(dsPtr, ns_inet_ntoa( > ((struct sockaddr_in *) ptr->ai_addr)->sin_addr)); > ptr = ptr->ai_next; > } > freeaddrinfo(res); > - status = NS_TRUE; > } > return status; > --- 347,354 ---- > Tcl_DStringAppendElement(dsPtr, ns_inet_ntoa( > ((struct sockaddr_in *) ptr->ai_addr)->sin_addr)); > + status = NS_TRUE; > ptr = ptr->ai_next; > } > freeaddrinfo(res); > } > return status; > *************** > *** 367,374 **** > char buf[2048]; > int result; > - int i = 0; > int h_errnop; > int status = NS_FALSE; > > #if defined(HAVE_GETHOSTBYNAME_R_6) > result = gethostbyname_r(host, &he, buf, sizeof(buf), &res, &h_errnop); > --- 367,375 ---- > char buf[2048]; > int result; > int h_errnop; > int status = NS_FALSE; > > + memset(buf, 0, sizeof(buf)); > + > #if defined(HAVE_GETHOSTBYNAME_R_6) > result = gethostbyname_r(host, &he, buf, sizeof(buf), &res, &h_errnop); > *************** > *** 385,389 **** > > if (result != 0) { > ! LogError("gethostbyname_r", h_errnop); > } else { > ptr = (struct in_addr *) he.h_addr_list[i]; > --- 386,390 ---- > > if (result != 0) { > ! LogError("gethostbyname_r", h_errnop); > } else { > ptr = (struct in_addr *) he.h_addr_list[i]; > *************** > *** 392,395 **** > --- 393,397 ---- > Tcl_DStringAppendElement(dsPtr, ns_inet_ntoa(ia)); > status = NS_TRUE; > + ptr = (struct in_addr *) he.h_addr_list[++i]; > } > } > *************** > *** 419,423 **** > he = gethostbyname(host); > if (he == NULL) { > ! LogError("gethostbyname", h_errno); > } else { > ptr = (struct in_addr *) he.h_addr_list[i]; > --- 421,425 ---- > he = gethostbyname(host); > if (he == NULL) { > ! LogError("gethostbyname", h_errno); > } else { > ptr = (struct in_addr *) he.h_addr_list[i]; > *************** > *** 426,429 **** > --- 428,432 ---- > Tcl_DStringAppendElement(dsPtr, ns_inet_ntoa(ia)); > status = NS_TRUE; > + ptr = (struct in_addr *) he.h_addr_list[++i]; > } > } > |
From: Zoran V. <zv...@ar...> - 2005-04-11 06:50:36
|
Am 11.04.2005 um 05:05 schrieb Stephen Deasey: > I guess this is an OSX problem? While looking at the configure tests, > I noticed that gethostbyname_r etc. are not used on Linux, even though > they're available. The standard call is thread safe, but only because > glibc puts a lock around everything. > > I wonder if for performance the *_r variants should always be > preferred...? > Actually, this happens only on Solaris 2.6 (yes, we still must support 2.6). No, the performance isn't the main reason. The main reason is other code using the non-mt-code. We can't just lock the call ourselves. We could do that if we were sitting in the libc, but we are not. Besides, this is/was a bug. Zoran |
From: Stephen D. <sd...@gm...> - 2005-04-13 02:08:53
|
On 4/11/05, Zoran Vasiljevic <zv...@ar...> wrote: >=20 > Am 11.04.2005 um 05:05 schrieb Stephen Deasey: >=20 > > I guess this is an OSX problem? While looking at the configure tests, > > I noticed that gethostbyname_r etc. are not used on Linux, even though > > they're available. The standard call is thread safe, but only because > > glibc puts a lock around everything. > > > > I wonder if for performance the *_r variants should always be > > preferred...? > > >=20 > Actually, this happens only on Solaris 2.6 (yes, we still must support > 2.6). No, the performance isn't the main reason. The main reason is > other code using the non-mt-code. We can't just lock the call ourselves. > We could do that if we were sitting in the libc, but we are not. >=20 > Besides, this is/was a bug. GETHOSTBYADDR_R isn't set when building on Linux, even though that function is available. The non-_r version is thread safe, as glibc does the locking. It will just serialize all calls and be slower. It completely doesn't matter because getnameinfo is used in preference... = :-) |