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 only works for file ports in Guile,
but fibers works for any port that exposes port-read-wait-fd or
port-write-wait-fd.

* fibers/io-wakeup.scm (readable?, writable?): Take a fd rather than a
port.
(try-ready): Take port-ready-fd, and use this when calling ready?.
(wait-until-port-readable-operation): Pass port-read-wait-fd to try-ready.
(wait-until-port-writable-operation): Pass writable? rather than
readable? and port-write-wait-fd to try-ready.
  • Loading branch information
Christopher Baines committed Sep 15, 2023
1 parent 46685fa commit 9a0369a
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 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)
"Test if PORT is writable."
(match (select (vector port) #() #() 0)
(define (readable? fd)
"Test if FD is writable."
(match (select (vector fd) #() #() 0)
((#() #() #()) #f)
((#(_) #() #()) #t)))

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

(define (try-ready ready? port)
(define (try-ready ready? port port-ready-fd)
(lambda ()
(and (ready? port) values)))
(and (ready? (port-ready-fd port)) 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 port-read-wait-fd) 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 writable? port port-write-wait-fd) 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 9a0369a

Please sign in to comment.