From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Newsgroups: gmane.lisp.guile.devel Subject: Re: non-blocking i/o in guile Date: Thu, 19 May 2016 17:30:32 +0200 Message-ID: <87k2iqt693.fsf@gnu.org> References: <87k2ish1k9.fsf@pobox.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1463674286 32446 80.91.229.3 (19 May 2016 16:11:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 19 May 2016 16:11:26 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu May 19 18:11:18 2016 Return-path: Envelope-to: guile-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 1b3QXb-000183-KM for guile-devel@m.gmane.org; Thu, 19 May 2016 18:11:15 +0200 Original-Received: from localhost ([::1]:51213 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3QXa-0007UY-Tp for guile-devel@m.gmane.org; Thu, 19 May 2016 12:11:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43518) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3PuX-00057E-4m for guile-devel@gnu.org; Thu, 19 May 2016 11:30:54 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b3PuS-0003FQ-SI for guile-devel@gnu.org; Thu, 19 May 2016 11:30:52 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:50356) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3PuS-0003FM-Jn for guile-devel@gnu.org; Thu, 19 May 2016 11:30:48 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1b3PuP-0000jE-Vm for guile-devel@gnu.org; Thu, 19 May 2016 17:30:46 +0200 Original-Received: from pluto.bordeaux.inria.fr ([193.50.110.57]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 19 May 2016 17:30:45 +0200 Original-Received: from ludo by pluto.bordeaux.inria.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 19 May 2016 17:30:45 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 44 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: pluto.bordeaux.inria.fr X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 1 Prairial an 224 de la =?utf-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-unknown-linux-gnu User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Cancel-Lock: sha1:Wt5P1+rURNWoJ4Hs4jCdh/I7ZhY= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.org gmane.lisp.guile.devel:18322 Archived-At: Hi! Andy Wingo skribis: > Now, how to make this fit with non-blocking I/O? Initially I thought > that it would be sufficient to add a kind of sentinel return value that > would indicate the equivalent of EWOULDBLOCK. Then we'd have to have > some interface to get a file descriptor or other waitable (more on this > later) from the port. That waitable could be added to a poll set, or we > could layer blocking I/O on top of nonblocking I/O by calling poll(2) in > a loop with the read or write. > > This would be pretty gnarly but I think it could have worked -- except > two things: blocking local file access, and Windows. I explain. > > It turns out that even if you set a file descriptor to nonblocking, and > you use only nonblocking operations on it, if that file descriptor is > backed by a local file system, operations on it will block. The FD will > always poll as readable/writable. Linux has this problem, and async I/O > (AIO) doesn't help; glibc implements AIO in user-space with a new thread > per AIO operation. Terrible. FreeBSD does the same but with kernel > threads, AFAIU. > > The upshot is that to reliably do non-blocking I/O over local files you > need to use thread pools. > > I was willing to punt on non-blocking local I/O (and I still am), I would definitely punt on this. One could argue that it’s “none of our business”, in a way. ;-) > but then Windows. Windows doesn't have "poll". But… Gnulib’s poll module has a Windows implementation. Would it work to the POSIXy approach you suggest above, use Gnulib, and enjoy? :-) I’m more reluctant to even bother about Windows now that it implements the Linux syscalls. WDYT? Ludo’.