Subject: Re: Integrating with libev

Re: Integrating with libev

From: Timo Teras <timo.teras_at_iki.fi>
Date: Wed, 25 Apr 2012 08:47:37 +0300

On Tue, 24 Apr 2012 12:23:40 -0400 Brian McFarland
<mcfarlandjb_at_gmail.com> wrote:

> Thanks Timo. That's a great example that confirms what i'm trying to
> do is feasible. Your design has prompted a few more questions.
>
> So correct me if I'm wrong, but it looks like the
> ares_socket_callback() function is called whenever the sockets are
> created as well?

Yes, it seems that state callback is invoked also on socket creation.
However, you cannot distinguish really if it's created or deleted there
since in both cases readable and writable are 0. If you need to
allocate stuff on socket creation, you need to use the sock_create_cb.
(Checked version 1.7.5.)

Though, it doesn't matter for my code; it is enough to get called when
the socket is first started to be monitored.

> How did you decide on keeping watchers for just 4 fd's at a time? Is
> there something in your ares_opts or inherent to the nature of c-ares
> architecture that allowed for this decision? It's also not entirely
> clear to me what happens if you exceed 4 fd's that need watching.

No particular reason. It limits the concurrency; and my code does not
expect to do many parallel queries. If there's more queries pending,
NHRP_BUG_ON triggers runtime assertion.

Though, hmm, looking at my code again after a year, it might have a bug
in it. The fds[i].fd is not reset to -1 after a fd is no longer
monitored.

-Timo
Received on 2012-04-25