]> git.eshelyaron.com Git - emacs.git/commitdiff
Small dns.el code cleanup
authorLars Ingebrigtsen <larsi@gnus.org>
Thu, 30 Jul 2020 00:38:00 +0000 (02:38 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Thu, 30 Jul 2020 03:32:16 +0000 (05:32 +0200)
* 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

index 53ea0b19b52afe9788869173621957dc0aa5b78b..e02c99ea0c3911d3ff87e91f338c52397a9e03ea 100644 (file)
@@ -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