Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com Date: Tue, 31 Oct 2000 12:52:21 -0800 (PST) From: Dustin Lang X-Sender: dustinl AT taz DOT cs DOT ubc DOT ca To: cygwin AT sources DOT redhat DOT com Subject: Asynchronous DNS - gethostbyname_r Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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 AT sourceware DOT cygnus DOT com