From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: claudio.bley@gmail.com (Claudio Bley) Newsgroups: gmane.emacs.devel Subject: Re: Calling 'select' from emacs_gnutls_pull Date: Fri, 22 Feb 2013 12:15:36 +0100 Message-ID: <87k3q0wqef.wl%claudio.bley@gmail.com> References: <83wqu8qyik.fsf@gnu.org> <87fw0w6yny.fsf@lifelogs.com> <83txpcqjzs.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII X-Trace: ger.gmane.org 1361531774 13081 80.91.229.3 (22 Feb 2013 11:16:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 22 Feb 2013 11:16:14 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Feb 22 12:16:37 2013 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 1U8qcF-0001ns-6K for ged-emacs-devel@m.gmane.org; Fri, 22 Feb 2013 12:16:35 +0100 Original-Received: from localhost ([::1]:38772 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8qbu-0005Ai-JN for ged-emacs-devel@m.gmane.org; Fri, 22 Feb 2013 06:16:14 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:35528) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8qbf-0004VP-Ez for emacs-devel@gnu.org; Fri, 22 Feb 2013 06:16:01 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U8qbd-0006V3-2v for emacs-devel@gnu.org; Fri, 22 Feb 2013 06:15:59 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:55168) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8qbc-0006Uu-Sj for emacs-devel@gnu.org; Fri, 22 Feb 2013 06:15:57 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1U8qbu-0001Ui-4C for emacs-devel@gnu.org; Fri, 22 Feb 2013 12:16:14 +0100 Original-Received: from 178-25-240-82-dynip.superkabel.de ([178.25.240.82]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 22 Feb 2013 12:16:14 +0100 Original-Received: from claudio.bley by 178-25-240-82-dynip.superkabel.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 22 Feb 2013 12:16:14 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 116 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 178-25-240-82-dynip.superkabel.de In-Reply-To: <83txpcqjzs.fsf@gnu.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/24.1.50 (i386-mingw-nt6.1.7601) MULE/6.0 (HANACHIRUSATO) 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:157260 Archived-At: Hi. At Sat, 16 Feb 2013 18:52:23 +0200, Eli Zaretskii wrote: > > > From: Ted Zlatanov > > Date: Sat, 16 Feb 2013 10:55:45 -0500 > > > > ...and there are comments accumulated over the years in that > > neighborhood. Claudio Bley contributed much of the original code here, > > including the piece you're referring to. The history is at > > > > http://comments.gmane.org/gmane.emacs.devel/136816 > > I've (re-)read that thread, but didn't find any rationale for calling > 'select'. Claudio, could you perhaps chime in? That was quite some time ago and, I'm afraid, my memory fails me at that. Looking at the code, I cannot see a strong reason calling select inside of emacs_gnutls_pull... Maybe it was indeed because of performance reasons, but more likely some kind of left-over from chasing a red herring while trying to figure out why it didn't work sometimes. However, applying the obvious patch: --- >8 --- --- src/w32.c Thu Feb 21 14:35:43 2013 +++ ../build/src/w32.c Fri Feb 22 08:32:35 2013 @@ -7837,27 +7837,9 @@ err = errno; + /* Translate the WSAEWOULDBLOCK alias EWOULDBLOCK to EAGAIN. */ if (err == EWOULDBLOCK) - { - /* Set a small timeout. */ - timeout = make_emacs_time (1, 0); - FD_ZERO (&fdset); - FD_SET ((int)fd, &fdset); - - /* Use select with the timeout to poll the selector. */ - sc = select (fd + 1, &fdset, (SELECT_TYPE *)0, (SELECT_TYPE *)0, - &timeout, NULL); - - if (sc > 0) - continue; /* Try again. */ - - /* Translate the WSAEWOULDBLOCK alias EWOULDBLOCK to EAGAIN. - Also accept select return 0 as an indicator to EAGAIN. */ - if (sc == 0 || errno == EWOULDBLOCK) - err = EAGAIN; - else - err = errno; /* Other errors are just passed on. */ - } + err = EAGAIN; emacs_gnutls_transport_set_errno (process->gnutls_state, err); --- >8 --- and made a few tests using POP3 and IMAP connections over TLS and HTTPS connections. Works good. I also prepared a small test driver, downloading a file 33 MiByte in size from a remote host (over VPN): ,----[ test_tls.el ] | (require 'gnutls) | | (when (gnutls-available-p) | (url-retrieve-synchronously "https://192.168.0.1/artifactory-2.4.1.zip")) | | (kill-emacs) `---- Here are some numbers running emacs with "-Q --load test_tls.el" a few times. Note, that using "--batch -Q --script test_tls.el" uses 100% CPU and exits with an out of memory error (I assume because the GC is never run since there is no event loop nor threads involved). Average for with-select key over 3 runs Version Number: Windows NT 5.1 (Build 2600) Exit Time: 1:00 am, Monday, January 1 1601 Elapsed Time: 0:00:35.208 Process Time: 0:00:05.822 System Calls: 659366 Context Switches: 138074 Page Faults: 61507 Bytes Read: 80719977 Bytes Written: 320584 Bytes Other: 908395 Average for without-select key over 3 runs Version Number: Windows NT 5.1 (Build 2600) Exit Time: 1:00 am, Monday, January 1 1601 Elapsed Time: 0:00:33.796 Process Time: 0:00:06.166 System Calls: 857893 Context Switches: 140154 Page Faults: 69061 Bytes Read: 99353998 Bytes Written: 2017152 Bytes Other: 1175082 -- Claudio -- Claudio