getaddrinfo() for threading instead of gethostbyname()

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: getaddrinfo() for threading instead of gethostbyname()
Date: 2003-09-15 03:55:29
Message-ID: 200309150355.h8F3tTT07860@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

When FreeBSD didn't have gethostbyname_r(), and gethostbyname() wasn't
thread-safe, Marc asked around and found out that the threaded solution
for this is to use getaddrinfo(). This makes sense because
getaddrinfo() is described as:

getaddrinfo () function is defined for protocol-independent nodename-
to-address translation. It performs functionality of gethostbyname(3)
and getservbyname(3), in more sophisticated manner.

A number of platforms have getpwuid_r(), but not gethostbyname_r(). I
now realize it is because they are assuming you arew using getaddrinfo(),
which has freeaddrinfo() to free the allocated memory in a thread-safe
manner.

Right now, we call gethostname() from two places:

port/getaddrinfo() (if backend)
port/thread.c::pqGethostbyname()

and pqGethostbyname() (thread-safe) is called only by:

port/getaddrinfo() (if frontend)
libpq/fe-secure.c

If we convert fe-secure.c to use getaddrinfo(), then all host address
lookups go through getaddrinfo().

Then, if we don't need our port/getaddrinfo(), we don't care about a
non-thread-safe gethostbyname() on that platform. This improves our
thread-safe support. Specifically, it prevents host name lookups from
be serialized by our pthread locks.

Once everything goes through getaddrinfo(), I will modify my thread test
program to test gethostbyname() threading _only_ if getaddrinfo()
doesn't exist.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2003-09-15 03:59:04 Re: FreeBSD Thread-safe functions ...
Previous Message Tom Lane 2003-09-15 03:01:29 Re: FreeBSD Thread-safe functions ...