From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lars Magne Ingebrigtsen Newsgroups: gmane.emacs.devel Subject: Asynchronous DNS Date: Sat, 23 Jan 2016 14:50:54 +0100 Organization: Programmerer Ingebrigtsen Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1453557081 28653 80.91.229.3 (23 Jan 2016 13:51:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 23 Jan 2016 13:51:21 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jan 23 14:51:11 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aMyat-00085M-7F for ged-emacs-devel@m.gmane.org; Sat, 23 Jan 2016 14:51:11 +0100 Original-Received: from localhost ([::1]:57431 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMyas-0005hc-L8 for ged-emacs-devel@m.gmane.org; Sat, 23 Jan 2016 08:51:10 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37029) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMyao-0005hT-O9 for emacs-devel@gnu.org; Sat, 23 Jan 2016 08:51:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aMyal-0004uK-G6 for emacs-devel@gnu.org; Sat, 23 Jan 2016 08:51:06 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:58022) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMyal-0004t4-8f for emacs-devel@gnu.org; Sat, 23 Jan 2016 08:51:03 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1aMyai-0007zS-HD for emacs-devel@gnu.org; Sat, 23 Jan 2016 14:51:00 +0100 Original-Received: from cm-84.215.1.64.getinternet.no ([84.215.1.64]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 23 Jan 2016 14:51:00 +0100 Original-Received: from larsi by cm-84.215.1.64.getinternet.no with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 23 Jan 2016 14:51:00 +0100 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: emacs-devel@gnu.org Original-Lines: 62 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: cm-84.215.1.64.getinternet.no Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAMFBMVEXRWf8G7esB9vn/APAA /Pv+G/+nfPr/AOsV4dYi0btjncP/Bf7zNP8B8/kA+fs2vLLQiq3cAAABjElEQVQ4jb2RLZPCMBBA V1VhYE6cJYOlpgKBu4mOQ4E4VYGtQOP4CT11DlHLoGowdVHnE9GJbXwVt7vloxztzM2JezTbZN9u UlrY9ABdyWSTJDCLZkmEi2g2iyK8GuY5RAf8Ifkhn+fEIecJ5D38g1hcxfKeOy4XCBwXXaw0tBYc VgVGrVkUlFxpfdItoCh0wb0a4EHcZgMNg9OTCGAAARDX/C8IguAx8X4VcRzz/bKOe/iDyLJsnd3Y r/dNZNFJv9j10BLbRzHsAUwnXwLFFO+mGTSdcr7kjsr6sDLGVqbytMagwBvvlVMeoaiUwRLvHGBC ca4iJ22zg5NAtdY7KZVzGD2DE8D9raf9uJOPsFihgI6r8FzcSilqNpaPA0uisoJW1Ga8tSzo4Suu IuU8ziWfwX9tGpaWH4I24jwJgZcVIhTcEU5UyB3CiLEQpZQluonzksqpA1/k+P5OR0MhMEsdre+x 3aKiMXqRb/DBpGlKY5dePtn29SKegfP5XOO9rutn8YP6E0s/O0TDN6Psk6p/9pJNAAAAAElFTkSu QmCC Mail-Copies-To: never User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) Cancel-Lock: sha1:51bT2YMmdr+8nNGlIZy/IdhPs2M= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:198641 Archived-At: I talked about this a few years ago, but I didn't get very far, so I thought I'd reopen the subject and actually implement something this time. The problem is a general one: Everything about network communication in Emacs is asynchronous, except name resolution. In many cases, this isn't really that much of a problem, because whatever Emacs is doing has to wait for the entire network process to finish (say, copying a file over tramp), so that one part is synchronous isn't very noticeable. The one place it's really noticeable is in eww. You go to a page, and then Emacs will freeze (sometimes for many seconds), and then Emacs will unfreeze and start inserting images into the page. The freeze bit is when it's doing name resolution in `make-network-process' by calling getaddrinfo or gethostbyname. I see four ways of implementing an async name resolution function: 1) Add a new `resolve-name' function that would fork Emacs, call getaddrinfo/gethostbyname, and do a callback once we get a reply. The problem is that a forked Emacs is a very strange thing, and is not something we otherwise do. I looked at this for a day last time, and I couldn't get it to work, really. Perhaps somebody else could, though. 2) Use one of the newer async C resolver libraries. This would not be available on all platforms, and would be Yet Another Dependency which I'm sure everybody would rather that we avoid. 3) Create a tiny helper program in lib-src that would read names from stdin and output resolves on stdout. It would use getaddrinfo/gethostbyname, and could very well be multithreaded, so that it could do name resolution on parallel. 4) Pick the data out of res_init to find the DNS servers, and then just use dns.el for name resolution. This would be trivial to implement, but may not respect the name resolutions settings on some operating systems. In either case, I envision anything that wants async name resolution to basically transform from (make-network-process :host "foo.bar" ...) to (resolve-name "foo.bar" (lambda (status ip) (make-network-process :host "foo.bar" :ip ip ...))) or something along those lines. That is -- pass in a preresolved IP address to `make-network-process'. (Or list of addresses in the case of multihomed hosts, of course. Details, details.) So what do you think? I'm up for implementing 3) or 4), but probably not 1) or 2), but I think 1) would be the cleanest way to implement this, if possible. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no