From 18a5e52eed67700b65681ce5007f121f9700f241 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Thu, 30 Jul 2020 02:38:00 +0200 Subject: [PATCH] Small dns.el code cleanup * lisp/net/dns.el (dns-query): Clean up code slightly by removing a macro and moving the code into the function itself. --- lisp/net/dns.el | 60 ++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/lisp/net/dns.el b/lisp/net/dns.el index 53ea0b19b52..e02c99ea0c3 100644 --- a/lisp/net/dns.el +++ b/lisp/net/dns.el @@ -355,25 +355,6 @@ Parses \"/etc/resolv.conf\" or calls \"nslookup\"." result)) ;;; Interface functions. -(defmacro dns-make-network-process (server) - `(let ((server ,server) - (coding-system-for-read 'binary) - (coding-system-for-write 'binary)) - (if (and - (fboundp 'make-network-process) - (featurep 'make-network-process '(:type datagram))) - (make-network-process - :name "dns" - :coding 'binary - :buffer (current-buffer) - :host server - :service "domain" - :type 'datagram) - ;; Older versions of Emacs do not have `make-network-process', - ;; and on MS-Windows datagram sockets are not supported, so we - ;; fall back on opening a TCP connection to the DNS server. - (open-network-stream "dns" (current-buffer) server "domain")))) - (defvar dns-cache (make-vector 4096 0)) (defun dns-query-cached (name &optional type fullp reversep) @@ -386,9 +367,6 @@ Parses \"/etc/resolv.conf\" or calls \"nslookup\"." (set (intern key dns-cache) result) result)))) -;; The old names `query-dns' and `query-dns-cached' weren't used in Emacs 23 -;; yet, so no alias are provided. --rsteib - (defun dns-query (name &optional type fullp reversep) "Query a DNS server for NAME of TYPE. If FULLP, return the entire record returned. @@ -409,17 +387,33 @@ If REVERSEP, look up an IP address." nil) (with-temp-buffer (set-buffer-multibyte nil) - (let* ((process (condition-case () - (dns-make-network-process (car dns-servers)) - (error - (message - "dns: Got an error while trying to talk to %s" - (car dns-servers)) - nil))) - (step 100) - (times (* dns-timeout 1000)) - (id (random 65000)) - (tcp-p (and process (not (process-contact process :type))))) + (let* ((process + (condition-case () + (let ((server (car dns-servers)) + (coding-system-for-read 'binary) + (coding-system-for-write 'binary)) + (if (featurep 'make-network-process '(:type datagram)) + (make-network-process + :name "dns" + :coding 'binary + :buffer (current-buffer) + :host server + :service "domain" + :type 'datagram) + ;; On MS-Windows datagram sockets are not + ;; supported, so we fall back on opening a TCP + ;; connection to the DNS server. + (open-network-stream "dns" (current-buffer) + server "domain"))) + (error + (message + "dns: Got an error while trying to talk to %s" + (car dns-servers)) + nil))) + (step 100) + (times (* dns-timeout 1000)) + (id (random 65000)) + (tcp-p (and process (not (process-contact process :type))))) (when process (process-send-string process -- 2.39.2