Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 Aug 1999 17:54:32 -0600
From:      Nate Williams <nate@mt.sri.com>
To:        "Louis A. Mamakos" <louie@TransSys.COM>
Cc:        ognir@humboldt1.com, steve_tarkalson@hotmail.com, bmcgover@cisco.com, dan@trinsec.com, hackers@FreeBSD.ORG
Subject:   Re: gethostbyaddr() and threads. 
Message-ID:  <199908092354.RAA22388@mt.sri.com>
In-Reply-To: <199908092322.TAA68246@whizzo.transsys.com>
References:  <199908092255.PAA08129@home.humboldt1.com> <199908092322.TAA68246@whizzo.transsys.com>

next in thread | previous in thread | raw e-mail | index | archive | help
> > ---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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199908092354.RAA22388>