@@ -340,7 +340,6 @@ class DataSink {
340340
341341 std::function<bool (const char *data, size_t data_len)> write;
342342 std::function<void ()> done;
343- std::function<bool ()> is_writable;
344343 std::ostream os;
345344
346345private:
@@ -3632,7 +3631,7 @@ inline bool write_content(Stream &strm, const ContentProvider &content_provider,
36323631
36333632 data_sink.write = [&](const char *d, size_t l) -> bool {
36343633 if (ok) {
3635- if (write_data (strm, d, l)) {
3634+ if (strm. is_writable () && write_data (strm, d, l)) {
36363635 offset += l;
36373636 } else {
36383637 ok = false ;
@@ -3641,14 +3640,14 @@ inline bool write_content(Stream &strm, const ContentProvider &content_provider,
36413640 return ok;
36423641 };
36433642
3644- data_sink.is_writable = [&](void ) { return ok && strm.is_writable (); };
3645-
36463643 while (offset < end_offset && !is_shutting_down ()) {
3647- if (!content_provider (offset, end_offset - offset, data_sink)) {
3644+ if (!strm.is_writable ()) {
3645+ error = Error::Write;
3646+ return false ;
3647+ } else if (!content_provider (offset, end_offset - offset, data_sink)) {
36483648 error = Error::Canceled;
36493649 return false ;
3650- }
3651- if (!ok) {
3650+ } else if (!ok) {
36523651 error = Error::Write;
36533652 return false ;
36543653 }
@@ -3680,18 +3679,21 @@ write_content_without_length(Stream &strm,
36803679 data_sink.write = [&](const char *d, size_t l) -> bool {
36813680 if (ok) {
36823681 offset += l;
3683- if (!write_data (strm, d, l)) { ok = false ; }
3682+ if (!strm. is_writable () || ! write_data (strm, d, l)) { ok = false ; }
36843683 }
36853684 return ok;
36863685 };
36873686
36883687 data_sink.done = [&](void ) { data_available = false ; };
36893688
3690- data_sink.is_writable = [&](void ) { return ok && strm.is_writable (); };
3691-
36923689 while (data_available && !is_shutting_down ()) {
3693- if (!content_provider (offset, 0 , data_sink)) { return false ; }
3694- if (!ok) { return false ; }
3690+ if (!strm.is_writable ()) {
3691+ return false ;
3692+ } else if (!content_provider (offset, 0 , data_sink)) {
3693+ return false ;
3694+ } else if (!ok) {
3695+ return false ;
3696+ }
36953697 }
36963698 return true ;
36973699}
@@ -3720,7 +3722,10 @@ write_content_chunked(Stream &strm, const ContentProvider &content_provider,
37203722 // Emit chunked response header and footer for each chunk
37213723 auto chunk =
37223724 from_i_to_hex (payload.size ()) + " \r\n " + payload + " \r\n " ;
3723- if (!write_data (strm, chunk.data (), chunk.size ())) { ok = false ; }
3725+ if (!strm.is_writable () ||
3726+ !write_data (strm, chunk.data (), chunk.size ())) {
3727+ ok = false ;
3728+ }
37243729 }
37253730 } else {
37263731 ok = false ;
@@ -3759,14 +3764,14 @@ write_content_chunked(Stream &strm, const ContentProvider &content_provider,
37593764 }
37603765 };
37613766
3762- data_sink.is_writable = [&](void ) { return ok && strm.is_writable (); };
3763-
37643767 while (data_available && !is_shutting_down ()) {
3765- if (!content_provider (offset, 0 , data_sink)) {
3768+ if (!strm.is_writable ()) {
3769+ error = Error::Write;
3770+ return false ;
3771+ } else if (!content_provider (offset, 0 , data_sink)) {
37663772 error = Error::Canceled;
37673773 return false ;
3768- }
3769- if (!ok) {
3774+ } else if (!ok) {
37703775 error = Error::Write;
37713776 return false ;
37723777 }
@@ -6544,8 +6549,6 @@ inline std::unique_ptr<Response> ClientImpl::send_with_content_provider(
65446549 return ok;
65456550 };
65466551
6547- data_sink.is_writable = [&](void ) { return ok && true ; };
6548-
65496552 while (ok && offset < content_length) {
65506553 if (!content_provider (offset, content_length - offset, data_sink)) {
65516554 error = Error::Canceled;
@@ -6717,7 +6720,6 @@ inline ContentProviderWithoutLength ClientImpl::get_multipart_content_provider(
67176720 bool has_data = true ;
67186721 cur_sink.write = sink.write ;
67196722 cur_sink.done = [&]() { has_data = false ; };
6720- cur_sink.is_writable = sink.is_writable ;
67216723
67226724 if (!provider_items[cur_item].provider (offset - cur_start, cur_sink))
67236725 return false ;
0 commit comments