Re: Asynchronous DNS name resolution / DNS timeouts
- From: "Maxim Yegorushkin" <maxim.yegorushkin@xxxxxxxxx>
- Date: 31 Mar 2006 10:53:15 -0800
root wrote:
Sometimes I find that when DNS name resolution is not immediately
successful, gethostbyname() may block for unacceptable time, causing my
client program to become unresponsive. My question is, how should I
implement either DNS timeouts, or totally asynchronous DNS name
resolution? Do I need to write a proper DNS client from scratch from the
RFC? This is worse on some platforms than others.
Also gethostbyname() is poor because it is returning a pointer to static
data structure, and I currently must use mutexes to protect this call in
the multithreaded code. My code must be portable across HP/UX, Irix,
AIX, Linux, Solaris, Tru64, and Windows, so I have minimal choice about
what functions to use (gethostbyname_r() not supported on everything)
Try calling alarm() before the call to gethostbyname(), so that it is
interrupted when the alarm timeout reaches and SIGALRM is sent to your
application.
.
- References:
- Prev by Date: Re: Socket Send
- Next by Date: Re: large struct cause segmentation fault
- Previous by thread: Asynchronous DNS name resolution / DNS timeouts
- Index(es):
Relevant Pages
|