From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marko Rauhamaa Newsgroups: gmane.lisp.guile.user,gmane.lisp.guile.devel Subject: Re: anyone define port types? Date: Sun, 19 Jun 2016 12:55:15 +0300 Message-ID: <874m8pwlj0.fsf@elektro.pacujo.net> References: <87y492mnjp.fsf@pobox.com> <87pots9tag.fsf@gnu.org> <87bn37wtf2.fsf@pobox.com> <20160612092513.3eb1c8a3@laptop.homenet> <8760t5mthu.fsf@pobox.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1466330188 18509 80.91.229.3 (19 Jun 2016 09:56:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 19 Jun 2016 09:56:28 +0000 (UTC) Cc: Ludovic =?utf-8?Q?Court?= =?utf-8?Q?=C3=A8s?= , guile-devel , guile-user To: Andy Wingo Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Jun 19 11:56:27 2016 Return-path: Envelope-to: guile-user@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 1bEZSt-0006Zc-80 for guile-user@m.gmane.org; Sun, 19 Jun 2016 11:56:27 +0200 Original-Received: from localhost ([::1]:38087 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bEZSs-0003a5-CA for guile-user@m.gmane.org; Sun, 19 Jun 2016 05:56:26 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55433) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bEZSO-0003UH-Jv for guile-user@gnu.org; Sun, 19 Jun 2016 05:55:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bEZSM-0007d3-BC for guile-user@gnu.org; Sun, 19 Jun 2016 05:55:55 -0400 Original-Received: from [2001:1bc8:1a0:5384:7a2b:cbff:fe9f:e508] (port=52582 helo=pacujo.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bEZSL-0007bx-VW for guile-user@gnu.org; Sun, 19 Jun 2016 05:55:54 -0400 Original-Received: from elektro.pacujo.net (192.168.1.200) by elektro.pacujo.net; Sun, 19 Jun 2016 12:55:17 +0300 Original-Received: by elektro.pacujo.net (sSMTP sendmail emulation); Sun, 19 Jun 2016 12:55:17 +0300 In-Reply-To: <8760t5mthu.fsf@pobox.com> (Andy Wingo's message of "Sun, 19 Jun 2016 11:13:17 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:1bc8:1a0:5384:7a2b:cbff:fe9f:e508 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:12649 gmane.lisp.guile.devel:18347 Archived-At: Andy Wingo : > The trouble is that AFAIU there is no way to make non-blocking input > work reliably with O_NONBLOCK file descriptors in the approach that > Guile has always used. > > [...] > > The problem with this is not only spurious wakeups, as you note, but > also buffering. Throwing an exception when reading in Guile 2.0 will > discard input buffers in many cases. Likewise when writing, you won't > be able to know how much you've written. Guile's POSIX support provides immediate access to most OS facilities. However, support for read(2) and write(2) seem to be missing. (Note that Python, for example, provides both buffered, native facilities and the low-level os.read() and os.write().) Sure, recv! and send are there, but asynchronous I/O is more general than socket communication. > For suspendable ports, you don't throw an exception: you just assume > the operation is going to work, but if you get EAGAIN / EWOULDBLOCK, > you call the current-read-waiter / current-write-waiter and when that > returns retry the operation. Since it operates on the lowest level of > bytes, it's reliable. Looping handles the spurious wakeup case. The POSIX system call simply returns whatever bytes are available at the moment. That paradigm works perfectly. IOW, if you have buffered 10 bytes and get an EGAIN, just return those 10 bytes. > Why not just (install-suspendable-ports!) and > > (parameterize ((current-read-waiter my-read-waiter)) ...) > > etc? It is entirely possible with Guile 2.1.3 to build an asynchronous > coroutine-style concurrent system in user-space using these > primitives. See the wip-ethread branch for an example implementation. I haven't thought it through if that callback paradigm would offer the same degrees of freedom as the return-whatever-you-have paradigm. It seems unnecessarily complicated, though. I would simply violate the letter of the R?RS port semantics in Guile and go with the POSIX semantics. It seems clear the R?RS port specification was written without considering asynchronous communication at all. Marko