From d010467ac3189f7d40bcce09f9daa6bc879866cd Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 6 Oct 2024 20:39:09 +0800 Subject: [PATCH] dns: use undeprecated c-ares API c-ares marked `ares_process()` deprecated in 1.28.1 in this change, we use `ares_process_fd()` in favor of the deprecated `ares_process()`. Refs #2197 Signed-off-by: Kefu Chai --- src/net/dns.cc | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/net/dns.cc b/src/net/dns.cc index 9984502e77..ba6f4db145 100644 --- a/src/net/dns.cc +++ b/src/net/dns.cc @@ -595,30 +595,28 @@ dns_resolver::impl::end_call() { void dns_resolver::impl::poll_sockets() { fd_set readers, writers; - int n = 0; + bool processed = false; dns_log.trace("Poll sockets"); - do { + for (;;) { // Retrieve the set of file descriptors that the library wants us to monitor. FD_ZERO(&readers); FD_ZERO(&writers); - n = ares_fds(_channel, &readers, &writers); + int nr_fds = ares_fds(_channel, &readers, &writers); - dns_log.trace("ares_fds: {}", n); + dns_log.trace("ares_fds: {}", nr_fds); - if (n == 0) { + if (nr_fds == 0) { break; } - n = 0; + int n = 0; - for (auto & p : _sockets) { - auto & e = p.second; - auto fd = p.first; - auto r = FD_ISSET(p.first, &readers); - auto w = FD_ISSET(p.first, &writers); + for (auto& [fd, e] : _sockets) { + auto r = FD_ISSET(fd, &readers); + auto w = FD_ISSET(fd, &writers); auto ra = e.avail & POLLIN; auto wa = e.avail & POLLOUT; @@ -626,19 +624,21 @@ dns_resolver::impl::poll_sockets() { (w ? "w" : ""), (ra ? "r" : ""), (wa ? "w" : "")); - if (!wa) { - FD_CLR(fd, &writers); - } - if (!ra) { - FD_CLR(fd, &readers); - } - if (FD_ISSET(fd, &writers) || FD_ISSET(fd, &readers)) { + ares_socket_t read_fd = r && ra ? fd : ARES_SOCKET_BAD; + ares_socket_t write_fd = w && wa ? fd : ARES_SOCKET_BAD; + if (read_fd != ARES_SOCKET_BAD || write_fd != ARES_SOCKET_BAD) { + ares_process_fd(_channel, read_fd, write_fd); ++n; } } - - ares_process(_channel, &readers, &writers); - } while (n != 0); + if (n == 0) { + break; + } + processed = true; + } + if (!processed) { + ares_process_fd(_channel, ARES_SOCKET_BAD, ARES_SOCKET_BAD); + } } dns_resolver::srv_records