Subject: [Patch] An alternative to ares_fds() and ares_getsock()

[Patch] An alternative to ares_fds() and ares_getsock()

From: Brad Spencer <spencer_at_jacknife.org>
Date: 2006-02-09

Ok, first off, I'll admit that I am using c-ares-1.3.0 and didn't
notice that what is to become 1.3.1 already has a new function called
ares_getsock(). But even after seeing that new function, I thought
I'd post my patch with yet another way to get file descriptors and see
if it generated any discussion.

I think the aim of ares_getsock() is to avoid having to write one
accessor for poll(), one for select(), one for epoll (my personal
choice), and so on. I actually use asynchronous single-threaded C++
most of the time, so I actually have an object that manages my epoll
calls for me, and it's interface is essentially watch(fd, eventFlags)
and ignore(fd, eventFlags), and it's smart enough to not do anything
if it's already doing that. Enough background.

So, I figured the way to solve everyone's problem at once was simple
to write ares_fds_enumerate() which takes a callback function that is
fired for each and every file descriptor to tell user code what flags
need to be monitored for the next blocking call.

This approach seems to have the benefit of not requiring the data to
fit in any arbitrary data structure, which among other things
eliminates the (serious, IMO) limitation of ares_getsock()'s only
being able to handle 16 fds. Thus, it works for whatever kind of
blocking you wait to do, and only costs a few C-callbacks, which will
hardly matter. Performance very much matters for my applications, and
I didn't think twice about this approach.

Anyway, I plan to maintain a patch for myself using this mechanism,
and I submit it this list in case folks care to adapt it in some form
for the mainline library. Thanks again for this library which has so
far proved to be simple and flexible.

BTW: I added comments in the patch versus writing man pages; I can
write the latter if desired.

-- 
----------------------------------------------------------
Brad Spencer - spencer@jacknife.org - "It's quite nice..."
"S.M.A.K.I.B.B.F.B." - A.J. Rimmer | http://jacknife.org/

Received on Thu Feb 9 05:36:01 2006