janneke pushed a commit to branch wip-mingw in repository guile. commit 944852777c79eac03b607403f54d950c3068ef48 Author: Jan (janneke) Nieuwenhuizen <jann...@gnu.org> 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 b/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))) (cond - (((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))