@@ -86,8 +86,7 @@ write_crlf(
8686{
8787 auto n = buffers::copy (
8888 mbs,
89- buffers::const_buffer (
90- " \r\n " , 2 ));
89+ buffers::const_buffer (" \r\n " , 2 ));
9190 ignore_unused (n);
9291 BOOST_ASSERT (n == 2 );
9392}
@@ -794,19 +793,21 @@ start_buffers(
794793 // start_init() already called
795794 style_ = style::buffers;
796795
797- const auto buffers_max = (std::min)(
798- std::size_t { 16 },
799- buf_gen_->count ());
800-
801796 if (!filter_)
802797 {
798+ // limit the batch size. any remaining buffers will
799+ // be appended to incrementally in subsequent calls
800+ // to the prepare function.
801+ const auto batch_size = (std::min)(
802+ std::size_t { 16 },
803+ buf_gen_->count ());
804+
805+ // none-chunked
803806 if (!is_chunked_)
804807 {
805- // no filter and no chunked
806-
807808 prepped_ = make_array (
808- 1 + // header
809- buffers_max ); // buffers
809+ 1 + // header
810+ batch_size ); // buffers
810811
811812 prepped_[0 ] = { m.ph_ ->cbuf , m.ph_ ->size };
812813 std::generate (
@@ -817,9 +818,8 @@ start_buffers(
817818 return ;
818819 }
819820
820- // no filter and chunked
821-
822- if (buf_gen_->is_empty ())
821+ // chunked with length 0
822+ if (batch_size == 0 )
823823 {
824824 prepped_ = make_array (
825825 1 + // header
@@ -838,8 +838,8 @@ start_buffers(
838838 return ;
839839 }
840840
841- // Write entire buffers as a single chunk
842- // since total size is known
841+ // write all buffers as a single chunk, since
842+ // the total size is known in advance.
843843
844844 auto const buf_size = buf_gen_->size ();
845845 auto const header_len =
@@ -871,7 +871,7 @@ start_buffers(
871871 prepped_ = make_array (
872872 1 + // header
873873 1 + // chunk header
874- buffers_max + // buffers
874+ batch_size + // buffers
875875 1 ); // buffer or (crlf and final chunk)
876876
877877 prepped_[0 ] = { m.ph_ ->cbuf , m.ph_ ->size };
@@ -882,7 +882,7 @@ start_buffers(
882882 [this ](){ return buf_gen_->next (); });
883883
884884 more_input_ = !buf_gen_->is_empty ();
885- // assigning the last slot
885+ // assign the last slot
886886 if (more_input_)
887887 {
888888 prepped_[prepped_.size () - 1 ] =
0 commit comments