From owner-freebsd-hackers Mon Aug 9 16:57: 3 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from ns.mt.sri.com (ns.mt.sri.com [206.127.79.91]) by hub.freebsd.org (Postfix) with ESMTP id 107911519C for ; Mon, 9 Aug 1999 16:57:00 -0700 (PDT) (envelope-from nate@mt.sri.com) Received: from mt.sri.com (rocky.mt.sri.com [206.127.76.100]) by ns.mt.sri.com (8.8.8/8.8.8) with SMTP id RAA14363; Mon, 9 Aug 1999 17:54:33 -0600 (MDT) (envelope-from nate@rocky.mt.sri.com) Received: by mt.sri.com (SMI-8.6/SMI-SVR4) id RAA22388; Mon, 9 Aug 1999 17:54:32 -0600 Date: Mon, 9 Aug 1999 17:54:32 -0600 Message-Id: <199908092354.RAA22388@mt.sri.com> From: Nate Williams MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: "Louis A. Mamakos" Cc: ognir@humboldt1.com, steve_tarkalson@hotmail.com, bmcgover@cisco.com, dan@trinsec.com, hackers@FreeBSD.ORG Subject: Re: gethostbyaddr() and threads. In-Reply-To: <199908092322.TAA68246@whizzo.transsys.com> References: <199908092255.PAA08129@home.humboldt1.com> <199908092322.TAA68246@whizzo.transsys.com> X-Mailer: VM 6.34 under 19.16 "Lille" XEmacs Lucid Reply-To: nate@mt.sri.com (Nate Williams) Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > ---Steve Tarkalson said: > > > this is solved by one of two methods: > > > 1-) require the caller of gethostbyaddr() to supply a pointer to > > > a hostent struct which will be filled. > > > or 2-) the library uses thread specific storage which is re-used in > > > each call. > > > > > You could malloc() a struct hostent for each call to > > gethostby*(), each time registering the hostent in some list along with the > > thread's PID. If the same thread calls gethostby*, use the same buffer, or > > allocate a new one if another thread calls it. Have a static function be called > > atexit to free all the mallocs. > > Yuk! > > If you're writing a multithreaded program, a slightly different API for > gethostbyname() is likely to be the least of your worries. Agreed. gethostbyname_r() on solaris requires the caller to provide the address to write into, which is IMO the correct solution. Yes, it's a different API. But, the other alternatives are worse. The user must be able to control his memory allocation. For example, in a typical networking application, gethostbyname() could be called thousands or millions of times, and allocating memory everytime that can't be cleaned up until the program exits is completely unacceptable. Nate To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message