Subject: Re: Integrating with libev

Re: Integrating with libev

From: Timo Teräs <timo.teras_at_iki.fi>
Date: Tue, 24 Apr 2012 15:56:53 +0200

On Mon, Apr 23, 2012 at 10:31 PM, Brian McFarland <mcfarlandjb_at_gmail.com> wrote:
> I'm using libev in my application and trying to figure out if c-ares is
> suitable for DNS.
>
> My general thinking is that I'll use a libev io watcher per socket created
> by c-ares.  Then I'll just need to call ares_process_fd when the watcher
> wakes up.  I'll also likely need a timer, which is probably as simple as
> reseting a libev timer to ares_timeout() every time an I/O callback wakes
> up.
>
> It looks like I can use the "ARES_OPT_SOCK_STATE_CB" to detect when I need
> to enable/disable my watchers (i.e. event listeners) for each socket.
>
> It also appears that ares_set_socket_callback can be used to detect when new
> sockets are created and in turn initialize my libev watchers.
>
> However, I'm not sure of the correct way to detect when sockets are closed
> so that I can safely destroy libev watchers.  Is there a callback I'm
> missing that provides that information?  If not, any thoughts on where to
> insert it?

I used libev + ares for my opennhrp project. See:
http://opennhrp.git.sourceforge.net/git/gitweb.cgi?p=opennhrp/opennhrp;a=blob;f=nhrp/nhrp_address.c;hb=HEAD

-Timo
Received on 2012-04-24