Question about integrating udns in Ruby EventMachine

Iñaki Baz Castillo ibc at aliax.net
Mon Feb 7 00:46:06 MSK 2011


2011/2/6 Michael Tokarev <mjt at tls.msk.ru>:
>> 4) The application must also invoke dns_timeouts() periodically to
>> trigger the execution of the callback when timeout occurs for a query
>> (so dns_status() returns DNS_E_TEMPFAIL).
>
> You call dns_timeouts() right before poll/select, to process
> any expired entries and to determine the timeout to use for
> poll/select call, as I demonstrated in my first reply, and
> as shown in example code.

Thanks for your response. Two points here:

- I cannot call dns_timeouts() before poll as EventMachine doesn't
allow it to me. I just can ask EventMachine to watch in the file
descriptor of udns and invoke dns_ioevent() when data is received. I
can also add a periodic timer in EventMachine (useful for invoking
dns_timeouts() periodically if required).

- EventMachine also watches other file descriptors
(TCP/UDP/UnixSocket) so I assume it doesn't block in poll, so
"timeout" argument is 0.


I'm checking ex-rdns.c and honestly I don't understand this:

    if (curq) {
      t = dns_timeouts(0, -1, now);
      t = poll(&pfd, 1, c * 1000);
      now = time(NULL);
      if (t) dns_ioevent(0, now);
    }

Value returned by dns_timeouts() is not used as "t" is overriden with
poll() result in next line, neither "t" is used within poll arguments,
do I miss something?




>> - I've realized that, in case of a non responding DNS server (i.e:
>> 1.2.3.4) then dns_timeouts() returns the number of second after next
>> retransmission of the request (which is not a real timeout yet as the
>> callback is not executed with DNS_E_TEMPFAIL). This is, my example
>
> The only place to use value returned by dns_timeouts() is to
> calculate time to pass to poll/select.  There's no other usage
> for that.

I expect you assume poll() must block for the ammount of seconds
returned by dns_timeouts(), am I right?
But in my case I cannot control poll() (EventMachine does it for me).
But I think the following can work (I would say it's lredy working in
my code):

- I start a periodic timer (each 8 seconds) which calls
dns_timeouts(). If dns_timeouts() returns -1 then my timer fires after
8 seconds, if it returns a positive value N then my timer will fire
after N seconds.

- After invoking dns_submit_xxxx I call dns_timeouts() and again
update the periodic timer expiration with the returned value (as
above).

Is it wrong? At least it's working in my cose, and for every cases
(good results, timeouts, retransmissions are properly sent after
4-8-16 seconds...). I insist that I have no access to poll()
invocation.



Thanks a lot again.



-- 
Iñaki Baz Castillo
<ibc at aliax.net>


More information about the udns mailing list