unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Ian Price <ianprice90@googlemail.com>
To: Daniel Hartwig <mandyke@gmail.com>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: [PATCH] read-response-body should return received data when any break happens
Date: Thu, 15 Mar 2012 18:37:04 +0000	[thread overview]
Message-ID: <877gylu2wf.fsf@Kagami.home> (raw)
In-Reply-To: <CAN3veRc9=7-oxLj3B48vJ8Zz+A4gRQAUMhh0iiQofymkOpB_NQ@mail.gmail.com> (Daniel Hartwig's message of "Fri, 16 Mar 2012 00:09:28 +0800")

Daniel Hartwig <mandyke@gmail.com> writes:

> So this is an interesting start.  The idea of buffering the transfer
> is great -- however, it falls short in this implementation because it
> is internal to read-response-body.
The buffering is useless, it's already performed by get-bytevector-n. In
this sense, it is also not internal to read-response-body

> Also, the whole business about passing the partial data out via an
> exception is very messy.
>
> What about also passing a bytevector to read-response-body?  The
> exception then only needs to mention how many bytes were read because
> the caller already has access to the bytevector aka the data.
>
> Consider this quick hack:
>
> (define* (read-response-body! r bv #:optional
>                               (start 0)
>                               (count (min (bytevector-length bv)
>                                           (response-content-length r))))
>   (and count
>        (let ((read (get-bytevector-n! (response-port r) bv start count)))
>          (if (= read count)
>              bv
>              (bad-response
>               "EOF while reading response body: ~a bytes of ~a (buffer)"
>               read count)))))
>
> which has all the features of your solution yet is much smaller and
> puts the caller in more explicit control of the buffering, which opens
> up many scenarios.
Removing the unnecessary buffering also makes it smaller. :P

> For example, reusing the same bytevector and looping over
> read-response-body! saving the results to disk each time.  This limits
> the memory use to the size of the bytevector *and* removes the copy
> operation from your implementation (bonus!).
If you wanted to do it that way, it'd be better to pass in the port
directly and cut out the middle man. 

-- 
Ian Price

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"



  reply	other threads:[~2012-03-15 18:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-11 15:35 [PATCH] read-response-body should return received data when any break happens Nala Ginrut
2012-03-15 16:09 ` Daniel Hartwig
2012-03-15 18:37   ` Ian Price [this message]
2012-03-15 18:48     ` Daniel Hartwig
2012-03-16  2:23       ` Nala Ginrut
2012-03-16  3:24         ` Daniel Hartwig
2012-03-16  3:31         ` Nala Ginrut
2012-03-15 18:31 ` Ian Price

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877gylu2wf.fsf@Kagami.home \
    --to=ianprice90@googlemail.com \
    --cc=guile-devel@gnu.org \
    --cc=mandyke@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).