Damn.  Sorry, I posted out of sync versions of code and output.  This is
correct:

(define bstr (make-shared-bytes 509 5))
(define rx-pipe-size 16777216)
(define-values (rx-in rx-out) (make-pipe rx-pipe-size))

(define (room-in-rx-pipe? bstr)
  (define avail (- rx-pipe-size (pipe-content-length rx-out)))
  (displayln (format "avail: ~a" avail))
  (<= (bytes-length bstr) avail))

(displayln (format "space available? ~a " (room-in-rx-pipe? bstr)))
(displayln (format "pipe content length: ~a" (pipe-content-length rx-out)))
(define num-bytes-written (write-bytes-avail* bstr rx-out))
(unless (eq? num-bytes-written (bytes-length bstr))
  (displayln (format "rx buffer overflow. pipe content length: ~a, written
~a, expected ~a"
                     (pipe-content-length rx-out) num-bytes-written
(bytes-length bstr))))

(displayln "done")

-------- output:

avail: 16777216
space available? #t
pipe content length: 0
rx buffer overflow. pipe content length: 15, written 15, expected 509
done

On Wed, Jun 16, 2021 at 2:11 PM George Neuner <gneun...@comcast.net> wrote:

>
> On 6/16/2021 1:19 PM, David Storrs wrote:
>
> I'm getting bytes off the wire and attempting to write them to a port.  I
> have a check in place to verify that the pipe has free space but when I
> attempt to reports that yes, there is space, and then it writes and fails
> regardless and I'm not sure why.  The following is a simplified version of
> the code but it produces the same results as the live version.
>
> I've dug through the docs on write-bytes-avail* and pipes and I'm
> scratching my head.  Any thoughts?
>
> ------- code
> #lang racket
> (define bstr (make-shared-bytes 509 5))
> (define rx-pipe-size 16777216)
> (define-values (rx-in rx-out) (make-pipe rx-pipe-size))
>
> (define (room-in-rx-pipe? bstr)
>   (define avail (- rx-pipe-size (pipe-content-length rx-out)))
>   (displayln (format "space available: ~a" avail))
>   (<= (bytes-length bstr) avail))
>
> (displayln (format "space available? ~a " (room-in-rx-pipe? bstr)))
> (define num-bytes-written (write-bytes-avail* bstr rx-out))
> (unless (eq? num-bytes-written (bytes-length bstr))
>   (displayln (format "rx buffer overflow. num-bytes-written ~a, expected
> ~a"
>                      num-bytes-written (bytes-length bstr))))
>
> (displayln "done")
> -------- /code
>
> The output is:
>
> ------- output
> avail: 16777216
> space available? #t
> pipe content length: 0
> rx buffer overflow. pipe content length: 15, written 15, expected 509
> done
> ------- /output
>
>
>
> I'm not sure what's going on either, but your output says the pipe
> contains 15 characters/bytes and THAT will cause *write-bytes-avail**  to
> fail ... it fails if there is existing buffered content.  I suspect that it
> will work if you substitute *write-bytes-avail*  (no *)  or have
> something read from the pipe before writing to it.
>
> I've never used Racket's pipes, but this looks very much like a connect
> handshake issue.
>
> George
>
> --
> 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/0619cc74-a15d-a0f2-38b7-09feeebf59c0%40comcast.net
> <https://groups.google.com/d/msgid/racket-users/0619cc74-a15d-a0f2-38b7-09feeebf59c0%40comcast.net?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CAE8gKocz8BkvRc%2BeDhDt0WpOmqzkeEYdoQ9cfacGJhNkXkNugg%40mail.gmail.com.

Reply via email to