Subject: Integrating with libev

Integrating with libev

From: Brian McFarland <mcfarlandjb_at_gmail.com>
Date: Mon, 23 Apr 2012 16:31:26 -0400

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?
Received on 2012-04-23