Lisp HUG Maillist Archive

STREAM:STREAM-FILL-BUFFER

Hi!

STREAM:STREAM-FILL-BUFFER is exported from the STREAM package but it's
not documented. I'd like to know if there's a way to find out how many
bytes (octets) have been read into the buffer after this function has
been called. Getting the buffer state and computing the difference
between the INPUT-LIMIT and INPUT-INDEX slots doesn't seem to be the
right thing.

(I'm trying to make chunked enconding work for PortableAllegroServe's
DO-HTTP-REQUEST function.)

Thanks,
Edi.


Re: STREAM:STREAM-FILL-BUFFER

Unable to parse email body. Email id is 1626

Re: STREAM:STREAM-FILL-BUFFER

On Thu, 27 Nov 2003 14:08:43 GMT, davef@xanalys.com wrote:

> You can use WITH-STREAM-INPUT-BUFFER (example below) and check the
> LIMIT and INDEX. Note that these values represent character units,
> not bytes (octets), although for BASE-CHAR SOCKET-STREAMs this will
> be the same thing.
>
> I don't know how you're getting the buffer state

  (slot-value stream 'stream::buffer-state)

> or why you think the difference between LIMIT and INDEX is not the
> right thing.

As I said, I was trying to fix a bug in the chunked encoding
implementation of Portable AllegroServe. I didn't know the code before
and just tried to get it to work for me. I found out about the buffer
state with LW's introspection tools but then realized that
WITH-STREAM-INPUT-BUFFER (which is used in the Portable AllegroServe
code) did what I need. So I gave it a try and failed. It turns out
that this was because of the caching you mention below which didn't
occur to me. (As I said: No docs, so I was just guessing and playing
around.)

> Be aware that WITH-STREAM-INPUT-BUFFER caches the value, so the form
> must be reentered after other stream functions such as
> STREAM-FILL-BUFFER have been called. Typically that means you need a
> loop like this:
>
> (loop (stream:with-stream-input-buffer (buffer index limit) stream
>         (if (> limit index) ; buffer contains something
>             (multiple-value-bind (new-index finished)
>                 (consume-some-of-the-buffer buffer index limit)
>               (setf index new-index)
>               (when finished
>                 (return)))
>           (unless (stream:stream-fill-buffer stream)
> 	    (end-of-file-before-work-finished)))))

Thanks for your help. Rudi Schlatte has since fixed the bug but I've
forwarded your advice to the Portable AllegroServe maintainers hoping
that it might be helpful.

Thanks again,
Edi.


Updated at: 2020-12-10 08:58 UTC