This is the mail archive of the cygwin@sources.redhat.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Asynchronous DNS - gethostbyname_r



Hi,

I'm working on a net application (a personal proxy server).  For a couple
of reasons (masochism may be one...), I've decided to use non-blocking
calls and select() rather than the standard accept()-fork() for handling
requests.

The main problem with this is DNS lookups, since the standard
gethostbyname() has no notion of being non-blocking.  I've decided to get
around this by creating a handful of pthreads to perform the lookups.  The
single main network thread adds a lookup request item onto a list, and the
"worker" lookup pthreads take a request off the list, perform the lookup,
and store the result in a cache list.

The problem with this is that the standard gethostbyname() call uses
static storage to return the result, so is not safe to use in multiple
pthreads.  There isn't really a way to work around this, so a new call has
been created, gethostbyname_r, which accepts a buffer in which the result
is placed.  (I'm not sure which standard (if any) specifies this call, but
it exists in glibc and also in the Sun machines at my school, so it must
be fairly widespread...).  Sadly, cygwin (and winsock) doesn't (seem
to) have this call.

I was going to write my own gethostbyname_r, but realized that cygwin's
gethostbyname just calls winsock's (as I might have expected if I'd given
it any thought...).

There as a GNU asynch DNS library which I considered using, but it expects
standard UNIX things like /etc/resolv.conf with DNS server IP addresses,
and I'd like my app to work basically transparently, since I want it to be
usable by dummies.

I was thinking of trying to hack up similar functionality by using the
WSAAsyncGetHostByName() call, which as you might expect does asynchronous
DNS lookups.  However, when the lookup completes it delivers a windows
message - hWnds and all those gnarly things.  I don't think I want to deal
with the utter frustration that is dealing with the windows API - that's
why I'm using cygwin in the first place!

Basically the options I'm looking at now is doing DNS lookups a la SQUID
(www.squid-cache.org): it forks about a dozen processes which exec an
external dns lookup program; the main program communicates with the
external program via pipes.  The external processes can block all they
like.

Any suggestions or comments are welcomed.

Thanks!
dstn.



--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]