Last active
May 17, 2017 03:27
-
-
Save milesrout/d4bd40ef3ab3910d0c879d14b14c8cf7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (do-read sock n) | |
(linux/do-syscall 'read (sock n 'linux/onoblock))) | |
(define (read sock n) | |
(let ((result (do-read sock n))) | |
(if (equal? result 'linux/ewouldblock) | |
(call-with-current-continuation | |
(lambda (cc) | |
(wait sock cc)) | |
result))) | |
;; Efficiently doing this requires keeping a queue of ready | |
;; tasks and a queue of not-ready tasks. You loop over the | |
;; ready tasks and run them until they wait, then push them | |
;; to the unready tasks. Then you loop over the unready tasks | |
;; and check if they're ready, if they are you push them to | |
;; a new ready queue and otherwise you push them to a new | |
;; unready queue. | |
(define (wait obj cont) | |
nil) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment