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? if
port is not a file port.
(wait-until-port-readable-operation): Pass port-read-wait-fd to
try-ready.
(wait-until-port-writable-operation): Pass port-write-wait-fd to
try-ready.
  • Loading branch information
Christopher Baines committed Sep 20, 2023
1 parent f8ec3c4 commit b9c73d8
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions fibers/io-wakeup.scm
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,24 @@

;; These procedure are subject to spurious wakeups.

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

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

(define (try-ready ready? port)
(define (try-ready ready? port port-ready-fd)
(lambda ()
(and (ready? port) values)))
(and (ready? (if (file-port? port)
port
(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 +113,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 writable? 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 b9c73d8

Please sign in to comment.