[Top][All Lists]

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

[Guile-commits] 09/25: Make `read-bytes' suspendable for socket reads on

From: Mike Gran
Subject: [Guile-commits] 09/25: Make `read-bytes' suspendable for socket reads on MinGW.
Date: Thu, 10 Nov 2022 18:06:17 -0500 (EST)

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

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

    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 a823f1d37..a451b63f1 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]