Skip to content

Commit

Permalink
io-wakeup: Use file descriptors when calling select.
Browse files Browse the repository at this point in the history
Rather than ports, since select doesn't work for all ports in Guile.

* fibers/io-wakeup.scm (readable?, writable?, try-ready): Take a fd
rather than a port.
(wait-until-port-readable-operation,
wait-until-port-writable-operation): Pass the fd to try-ready?.
  • Loading branch information
Christopher Baines committed Sep 11, 2023
1 parent 46685fa commit ab1f9de
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions fibers/io-wakeup.scm
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@

;; These procedure are subject to spurious wakeups.

(define (readable? port)
(define (readable? fd)
"Test if PORT is writable."
(match (select (vector port) #() #() 0)
(match (select (vector fd) #() #() 0)
((#() #() #()) #f)
((#(_) #() #()) #t)))

(define (writable? port)
(define (writable? fd)
"Test if PORT is writable."
(match (select #() (vector port) #() 0)
(match (select #() (vector fd) #() 0)
((#() #() #()) #f)
((#() #(_) #()) #t)))

(define (try-ready ready? port)
(define (try-ready ready? fd)
(lambda ()
(and (ready? port) values)))
(and (ready? fd) values)))

(define (make-wait-operation try-fn schedule-when-ready port port-ready-fd)
(letrec ((this-operation
Expand Down Expand Up @@ -110,11 +110,11 @@ of the operation."

(define (wait-until-port-readable-operation port)
"Make an operation that will succeed when PORT is readable."
(make-read-operation (try-ready readable? port) port))
(make-read-operation (try-ready readable? (port-read-wait-fd port)) port))

(define (wait-until-port-writable-operation port)
"Make an operation that will succeed when PORT is writable."
(make-write-operation (try-ready readable? port) port))
(make-write-operation (try-ready readable? (port-write-wait-fd port)) port))

(define (with-x-waiting-is-failure port current-x-waiter try-fn)
"Return a thunk like TRY-FN, except that it also fails when
Expand Down

0 comments on commit ab1f9de

Please sign in to comment.