using multiple c-ares channels in a select() loop

336 Views Asked by At

I'm new to the c-ares library and I want to extend the example below such that I can simultaneously wait for multiple queries to complete. Here is a working example:

void processChannelBlocking(Channel &c) {
    int nfds, count;
    fd_set readers, writers;
    struct timeval tv;
    while (c.isRunning()) {
        FD_ZERO(&readers);
        FD_ZERO(&writers);
        tv.tv_sec  = std::numeric_limits<typeof(tv.tv_sec)>::max();
        tv.tv_usec = std::numeric_limits<typeof(tv.tv_usec)>::max();
        nfds = c.updateFDs(&readers, &writers);
        if (nfds == 0)   break;
        c.updateTimeout(&tv);
        count = select(nfds, &readers, &writers, NULL, &tv);
        c.process(&readers, &writers);
        std::cout<<"loop"<<std::endl;
    }
}
  • updateFDs() gets the FDs for a channel
  • updateTimeout() lowers the timeout to what a channel requires
  • process() is ares_process()

I can easily setup select() to wait for multiple channels, but when select() returns, how can I tell which channel to call ares_process on?

0

There are 0 best solutions below