From: Alviro Iskandar Setiawan <[email protected]>
To: Ammar Faizi <[email protected]>
Cc: Muhammad Rizki <[email protected]>,
Kanna Scarlet <[email protected]>,
"GNU/Weeb Mailing List" <[email protected]>
Subject: Re: [PATCH v1 17/22] chnet: Initial chunked request body support
Date: Mon, 22 Aug 2022 05:13:51 +0700 [thread overview]
Message-ID: <CAOG64qMDES9GZ4owbpWd-9xQjmeh-ZfCNz+p7hDBHWywSQaxSg@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
On Sun, Aug 21, 2022 at 6:24 PM Ammar Faizi wrote:
> +int CHNetDataStreamChunked::ReadInternal(net::IOBuffer *buf, int read_size_arg)
> +{
> + size_t read_size;
> + char *ptr;
> + int ret;
> +
> + if (unlikely(read_size_arg < 0))
> + return net::ERR_IO_PENDING;
> +
> + if (unlikely(is_eof_ || !read_size_arg))
> + return 0;
> +
> + ret = 0;
> + ptr = buf->data();
> + read_size = (size_t)read_size_arg;
> +
> + std::unique_lock<std::mutex> lk(buf_lock_);
> + while (read_size) {
> + struct net::CHNetDataStreamChunked::buf *b;
> + size_t copy_size;
> +
> + if (unlikely(!buf_queue_.size())) {
> + /*
> + * At this point, the buffer is empty.
> + *
> + * Wait for the buffer queue to be
> + * filled in.
> + */
> + being_waited_.store(true, std::memory_order_release);
> + buf_cond_.wait(lk, [this]{ return buf_queue_.size(); });
> + being_waited_.store(false, std::memory_order_release);
> + }
> +
> + b = buf_queue_.front();
> + if (b->len_ == -(size_t)1UL) {
> + is_eof_ = true;
> + break;
> + }
> +
> + copy_size = b->len_ - cur_pos_;
> + if (copy_size > read_size)
> + copy_size = read_size;
> +
> + memcpy(ptr, &b->buf_[cur_pos_], copy_size);
> + ptr += copy_size;
> + ret += copy_size;
> + read_size -= copy_size;
> + buf_queue_.head_++;
> + }
> +
> + if (unlikely(is_eof_))
> + SetIsFinalChunk();
> +
> + if (unlikely(!ret && !is_eof_))
> + return net::ERR_IO_PENDING;
> +
> + return ret;
> +}
I think you shouldn't return net::ERR_IO_PENDING, just sleep on the
condition variable if the buffer is not ready yet, it is legal to
sleep on ReadInternal(), why spend time spinning on -EAGAIN?
You can end in OnReadCompleted() if you sleep on the condition
variable and wait for it to get signaled:
https://source.chromium.org/chromium/chromium/src/+/main:net/base/upload_data_stream.cc;l=82-87;drc=5eda14f193ef3e0131aad2f31ae172c0001b3f6d?q=upload_data_stream.cc&ss=chromium%2Fchromium%2Fsrc
tq
-- Viro
next prev parent reply other threads:[~2022-08-21 22:14 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-21 11:24 [PATCH v1 00/22] ncns updates Ammar Faizi
2022-08-21 11:24 ` [PATCH v1 01/22] chnet: Add initial request body support Ammar Faizi
2022-08-21 11:24 ` [PATCH v1 02/22] chnet: node: Add set_user_data support on SQE Ammar Faizi
2022-08-21 11:24 ` [PATCH v1 03/22] tests/js/ring: Update the unit test to utilize set_user_data Ammar Faizi
2022-08-21 11:24 ` [PATCH v1 04/22] binding.gyp: Add `-ggdb3` flag for better debugging experience Ammar Faizi
2022-08-21 11:24 ` [PATCH v1 05/22] binding.gyp: Add `-Wno-enum-constexpr-conversion` flag Ammar Faizi
2022-08-21 11:24 ` [PATCH v1 06/22] chnet: node: Add set_method function to set HTTP method Ammar Faizi
2022-08-21 11:24 ` [PATCH v1 07/22] chnet: node: Add get_error function to return the error string Ammar Faizi
2022-08-21 11:24 ` [PATCH v1 08/22] chnet: node: Add set_payload function to set HTTP req body Ammar Faizi
2022-08-21 11:24 ` [PATCH v1 09/22] tests/js/ring: Add simple HTTP POST request example in NodeJS Ammar Faizi
2022-08-21 11:24 ` [PATCH v1 10/22] chnet: Split construct URL req creation into a new function Ammar Faizi
2022-08-21 11:24 ` [PATCH v1 11/22] chnet: Add set request header support Ammar Faizi
2022-08-21 11:24 ` [PATCH v1 12/22] chnet: node: Fix unused variable warning Ammar Faizi
2022-08-21 11:24 ` [PATCH v1 13/22] chnet: node: Add set request header function in NodeJS Ammar Faizi
2022-08-21 11:24 ` [PATCH v1 14/22] tests/js/ring: Add more set header function test Ammar Faizi
2022-08-21 11:24 ` [PATCH v1 15/22] chnet: node: Don't use static counter for data ID Ammar Faizi
2022-08-21 11:24 ` [PATCH v1 16/22] tests/js/ring: Add JavaScript class wrapper example Ammar Faizi
2022-08-21 11:24 ` [PATCH v1 17/22] chnet: Initial chunked request body support Ammar Faizi
2022-08-21 22:13 ` Alviro Iskandar Setiawan [this message]
2022-08-22 3:08 ` Ammar Faizi
2022-08-21 11:24 ` [PATCH v1 18/22] chnet: Rework the chunked request body interface Ammar Faizi
2022-08-21 22:20 ` Alviro Iskandar Setiawan
2022-08-21 11:24 ` [PATCH v1 19/22] chnet: ring: Refactor the ring completely Ammar Faizi
2022-08-21 11:24 ` [PATCH v1 20/22] chnet: Use busy-waiting for signal waiter Ammar Faizi
2022-08-21 22:29 ` Alviro Iskandar Setiawan
2022-08-21 11:24 ` [PATCH v1 21/22] chnet: ring: Bump max_entry to 2G Ammar Faizi
2022-08-21 11:24 ` [PATCH v1 22/22] tests/cpp: Delete basic.cpp as it's no longer relevant Ammar Faizi
2022-08-21 22:21 ` Alviro Iskandar Setiawan
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAOG64qMDES9GZ4owbpWd-9xQjmeh-ZfCNz+p7hDBHWywSQaxSg@mail.gmail.com \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/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