diff options
author | Jan (janneke) Nieuwenhuizen <janneke@gnu.org> | 2020-03-27 21:29:23 +0100 |
---|---|---|
committer | Michael Gran <spk121@yahoo.com> | 2022-11-10 10:33:54 -0800 |
commit | fe4e19a22aa1807473e6e39119ece02df9aa56c7 (patch) | |
tree | 010ce18091a45f6354a03fb4462cdfbef3cda763 | |
parent | 9bfd0b544f6455f64f751500e5a7e207e9c1a681 (diff) | |
download | guile-fe4e19a22aa1807473e6e39119ece02df9aa56c7.tar.gz |
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.
-rw-r--r-- | module/ice-9/suspendable-ports.scm | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/module/ice-9/suspendable-ports.scm b/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))) (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)) |