>>>>> "j" == john <[EMAIL PROTECTED]> writes:
j> The blocking nature of gethosbyname is well-known and solutions are
j> well-understood. The 'standard' solution (employed by netscape and
j> squid among others) is to fork one or more 'helper' processes. The
j> helper calls gethostbyname and the main app communicates with it
j> through a socket or pipe, so the main app can do other things while
j> the helper works.
j> Another solution might be to send a query to a resolver directly and
j> trigger an io Event upon recipt of a reply. Net::DNS comes to mind.
j> This would fit neatly into the structure I already have, i.e.,
j> organize the interaction with the nameserver via Events.
i solved this in a crawler i wrote in c by using threads and pipes. the
event loop was one i wrote in c for this project. to handle dns, we
created a pipe which was only inside this single process. one side was
watched for data in the main event loop. the other side was watched by a
set of threads. each thread did a blocking read on the pipe. when a dns
request was made in the main event loop, a structure was created and its
pointer was written to the pipe. a thread would read those 4 bytes, wake
up and do the request. when it was done, it would write the results into
the structure (it owned it then so no locks needed) and then wrote its
address to the pipe (in the other direction). the main event loop would
detect the data and trigger the code to read the structre address. then
the dns results would be processed.
this works very well. now, translating it to perl would be reasonably
straightforward but perl's threads are broken and you can't write
references directly into a pipe.
but the design is not far from what you want. fork off a set of child
processes, each with a main loop that reads from stdin writes to
stdout. you can test these easily off line. they read a dns address on a
single line and print the results back on a single line.
then you just have to make sure the i/o of the process will be available
in your main event loop. use IPC::open2 to fork the processes.
if you could manage Net::DNS's io with event.pm you could do that. i
think POE has some event based dns lookup. stem will have that for sure
at some point.
uri
--
Uri Guttman --------- [EMAIL PROTECTED] ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org