[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 09/12: DRAFT Make `read-bytes' suspendable for socket re

From: Jan Nieuwenhuizen
Subject: [Guile-commits] 09/12: DRAFT Make `read-bytes' suspendable for socket reads on MinGW.
Date: Mon, 30 Aug 2021 10:06:04 -0400 (EDT)

janneke pushed a commit to branch wip-mingw
in repository guile.

commit 825433059bb9ca6efb0ee222817824877e133f61
Author: Jan (janneke) Nieuwenhuizen <>
AuthorDate: Fri Mar 27 21:29:23 2020 +0100

    DRAFT Make `read-bytes' suspendable for socket reads on MinGW.
    On MinGW, port-read will block on sockets if no data is available.
    Avoid blocking by using select first.
    * module/ice-9/suspendable-ports.scm (read-bytes): For socket ports,
    guard port-read with select.
 module/ice-9/suspendable-ports.scm | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/module/ice-9/suspendable-ports.scm 
index a823f1d..a451b63 100644
--- a/module/ice-9/suspendable-ports.scm
+++ b/module/ice-9/suspendable-ports.scm
@@ -68,8 +68,12 @@
 (define (wait-for-writable port) ((current-write-waiter) port))
 (define (read-bytes port dst start count)
+  (define (socket? port)
+    (string-prefix? "#<input-output: socket" (format #f "~a" port)))
-   (((port-read port) port dst start count)
+   ((and (or (not (socket? port))
+             (pair? (car (select (list port) '() '() 0 0))))
+         ((port-read port) port dst start count))
     => (lambda (read)
          (unless (<= 0 read count)
            (error "bad return from port read function" read))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]