Re: Equivalent of gethostbyname_r for Mac OS X?
Re: Equivalent of gethostbyname_r for Mac OS X?
- Subject: Re: Equivalent of gethostbyname_r for Mac OS X?
- From: Alexey Proskuryakov <email@hidden>
- Date: Wed, 03 May 2006 12:56:32 +0400
- Thread-topic: Equivalent of gethostbyname_r for Mac OS X?
On 03.05.2006 05:18, "Tron Thomas" <email@hidden> wrote:
> I work on a cross platform project that is multithreaded. The code
> base wants to call gethostbyname_r as a thread safe way of connecting
> to a host sever. However, this function is not supported on Mac OS
> X. What is the equivalent thread safe way to accomplish the same
> functionality?
This isn't documented AFAIK, but Darwin gethostbyname uses thread local
storage, and is thus thread safe. Last time when this topic was discussed
here, an Apple employee mentioned that there already was a Radar to fix the
man page.
-----------------------------------------------
The Mac OS X implementations of a number of routines found in
libSystem, including getpwnam and getpwuid, have been modified to be
thread-safe. Rather than returning a pointer to a static data
structure, these routines allocate a structure for the returned value
that is stored in thread-specific memory. The memory is recycled (by
each thread) every time you make a call to one of these routines.
That allows you to use these APIs safely in multi-threaded applications.
The specific routines in the Libinfo project (see Libinfo/
lookup.subproj/lu_*.c) that maintain thread-specific memory for
results are:
- alias_getbyname alias_getent alias_setent alias_endent
- bootp_getbyether bootp_getbyip
- bootparams_getbyname bootparams_getent bootparams_setent
bootparams_endent
- getfsbyname getfsspec getfsfile getfsent setfsent endfsent
- initgroups getgrnam getgrgid getgrent setgrent endgrent
- gethostbyaddr gethostbyname gethostbyname2 gethostent sethostent
endhostent
- getipnodebyname getipnodebyaddr
- innetgr getnetgrent setnetgrent endnetgrent
- getnetbyaddr getnetbyname getnetent setnetent endnetent
- prdb_getbyname prdb_get prdb_set prdb_end
- getprotobyname getprotobynumber getprotoent setprotoent endprotoent
- getrpcbyname getrpcbynumber getrpcent setrpcent endrpcent
- getservbyport getservbyname getservent setservent endservent
- getpwnam getpwuid getpwent setpwent endpwent
-----------------------------------------------
- WBR, Alexey Proskuryakov
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden