Subject: Problem in adig when used both ARES_FLAG_USEVC and ARES_FLAG_STAYOPEN flags.

Problem in adig when used both ARES_FLAG_USEVC and ARES_FLAG_STAYOPEN flags.

From: Alexey Simak <alexeysimak_at_gmail.com>
Date: Thu, 12 Feb 2009 15:29:27 +0200

Hi,

adig hangs when both ARES_FLAG_USEVC and ARES_FLAG_STAYOPEN
flags are used.

Reason:
Since tcp socket is not closed when all queries are done
ares_fds() functions sets tcp socket to read_fds and returns 1.
So we leave the next loop only if server closes the connection:

  /* Wait for all queries to complete. */
  while (1)
    {
      FD_ZERO(&read_fds);
      FD_ZERO(&write_fds);
      nfds = ares_fds(channel, &read_fds, &write_fds);
      if (nfds == 0) {
        break;
      }
      tvp = ares_timeout(channel, NULL, &tv);
      count = select(nfds, &read_fds, &write_fds, NULL, tvp);
      if (count < 0 && SOCKERRNO != EINVAL)
        {
          perror("select");
          return 1;
        }
      ares_process(channel, &read_fds, &write_fds);
    }

Is there any other way we can be notified that all queries
are done and we can leave the loop?

Thanks,
Alexey Simak
Received on 2009-02-12