Question about integrating udns in Ruby EventMachine

Michael Tokarev mjt at tls.msk.ru
Tue Feb 1 13:57:18 MSK 2011


01.02.2011 13:42, Iñaki Baz Castillo wrote:
> 2011/2/1 Michael Tokarev <mjt at tls.msk.ru>:

>> ..but this part - I don't understand it.  Why do you want to "stole"
>> a filedescriptor from udns, why notify_readable() can't call udns
>> routine directly?
> 
> I meant that I need the file descriptor (maybe just the file
> descriptor number) to give it to EventMachine so it attachs it in the
> reactor and performs non blocking read on it.
> Maybe I miss something. If not, is it possible to get a pointer to the
> file descriptor used by udns? or maybe just the file descriptor
> number? (an integer I epect).

File descriptor is just an integer.  And this is THE object which
is used in udns to send and receive data AND to communicate with
the rest of application -- application needs to call dns_ioevent()
when the file descriptor in question is ready to be read.

>> Also, don't forget about timeouts (timers).
> 
> Ok. udns would call dns_timeouts() function.
> At Ruby level EventMachine provides timers so I can realized that a
> DNS query has not been completed in N seconds.

It's exactly the other way around.  udns knows when next query
will expire, your application calls provided function -- dns_timeouts() --
to perform two tasks: 1) process expired queries, and 2) determine
when next query will expire.  The second case is used in the
main event loop to determine how much time we can sleep waiting
for next event.

Please read example source code, like ex-rdns.c, to see how it
works.  So far I understand that you haven't looked at it at
all - based on both cases above (filedescriptor and timeouts).

Thanks.

/mjt


More information about the udns mailing list