On 6/16/2021 7:01 PM, Shu-Hung You wrote:
Out of curiosity, I wrapped David's code in a loop and tried to write 509 bytes in each iteration. From the output, it looks like CS doesn't implement pipes using a fixed-size buffer. I'm also not sure how many different buffers there are. I think this has something to do with George's question. :
Continuing in this vein, it seems that the count of bytes written starts small and then doubles with each successive write until finished (or until the buffer fills). I'm guessing this has to do with thread scheduling applied to I/O ... ie. try a short write (minimum quantum), and if it isn't finished try a longer write (longer quantum) ???
(define msg-size 15700) (define bstr (make-bytes msg-size 42)) (define rx-pipe-size 16384) (define-values (rx-in rx-out) (make-pipe rx-pipe-size)) (define (available?) (- rx-pipe-size (pipe-content-length rx-out))) (let loop ((start 0) (full? #f)) (cond [full? (displayln "buffer full")] [(>= start msg-size) (displayln "done")] [else (let ((written (write-bytes-avail* bstr rx-out start))) (printf "written: ~a starting at ~a~n" written start) ; (printf "available: ~a~n" (available?)) (loop (+ start written) (= written 0)) ) ])) written: 15 starting at 0 written: 16 starting at 15 written: 32 starting at 31 written: 64 starting at 63 written: 128 starting at 127 written: 256 starting at 255 written: 512 starting at 511 written: 1024 starting at 1023 written: 2048 starting at 2047 written: 4096 starting at 4095 written: 7509 starting at 8191 done With the "msg" size changed to exceed the buffer: written: 15 starting at 0 written: 16 starting at 15 written: 32 starting at 31 written: 64 starting at 63 written: 128 starting at 127 written: 256 starting at 255 written: 512 starting at 511 written: 1024 starting at 1023 written: 2048 starting at 2047 written: 4096 starting at 4095 written: 8192 starting at 8191 written: 1 starting at 16383 written: 0 starting at 16384 buffer full -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/6b252cfe-ca16-073b-5164-1bb784095825%40comcast.net.