From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [180.246.144.41]) by gnuweeb.org (Postfix) with ESMTPSA id 9C699807CA; Wed, 17 Aug 2022 13:35:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1660743341; bh=xXGPSOC3cVF0mRbaFWWFhMAd3Iav6Zn6f2VegiUEb9w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EPpKBd8uprNi4v9XfCd2o9MkvP55xfl4joJZ1vd0MIxScU6qgFFAxQk2zd/aEDJoD NFIT8bUULdvgLrarM6APcwowFYQAfEmDUZur6K6ooEbPI7KyYHfRLK8ZVRWSzs667h +Y99sEZJ+cuz61W4/2lUkipsglWGhjXG0t+XEJUaoDVnHDNILUFzg2VvDIAF2dS+AW XA9JbR0Gbxsd5qiWcTiu23wltUCWpUQ0IkagvdWaSp4j4NkXzfI/hHVptZNSIIDchN PDanEj093TWiOwz0dW+A8RavXRU6azcDIBT8CjCmIFR9EArQXJvI4hft/ng7ULzB4K hgOswaCZ20loQ== From: Ammar Faizi To: Alviro Iskandar Setiawan Cc: Ammar Faizi , GNU/Weeb Mailing List Subject: [PATCH ncns v1 2/2] chnet: Set error string when the Chromium hits net error Date: Wed, 17 Aug 2022 20:35:22 +0700 Message-Id: <20220817133522.1339809-3-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220817133522.1339809-1-ammarfaizi2@gnuweeb.org> References: <20220817133522.1339809-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Translate the error code to string when the Chromium hits a net error. This makes debugging easier for the callers because now we can know what the returned error code means, easily. Signed-off-by: Ammar Faizi --- chnet/chnet.cc | 11 +++++++++++ chnet/chnet.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/chnet/chnet.cc b/chnet/chnet.cc index c870e05..9d19882 100644 --- a/chnet/chnet.cc +++ b/chnet/chnet.cc @@ -149,6 +149,9 @@ int CHNetDelegate::Read(int size) void CHNetDelegate::OnResponseStarted(URLRequest *url_req, int net_err) { + if (unlikely(net_err < 0)) + SetError(net_err); + if (cb.response_started_) cb.response_started_(cb.response_started_data_, url_req, net_err); @@ -156,11 +159,19 @@ void CHNetDelegate::OnResponseStarted(URLRequest *url_req, int net_err) void CHNetDelegate::OnReadCompleted(URLRequest *url_req, int bytes_read) { + if (unlikely(bytes_read < 0)) + SetError(bytes_read); + read_ret_.store(bytes_read); if (cb.read_completed_) cb.read_completed_(cb.read_completed_data_, url_req, bytes_read); } +void CHNetDelegate::SetError(int err_code) +{ + err_ = "chromium_net_err:" + ErrorToString(err_code); +} + } /* namespace net */ CHNet::CHNet(void) diff --git a/chnet/chnet.h b/chnet/chnet.h index f91b25b..15ba8cd 100644 --- a/chnet/chnet.h +++ b/chnet/chnet.h @@ -26,6 +26,7 @@ #include "net/url_request/url_request_context_builder.h" #include "net/url_request/url_request_context.h" #include "net/url_request/url_request.h" +#include "net/base/net_errors.h" #define CHNET_EXPORT COMPONENT_EXPORT(CHNET) #else /* #ifdef __FOR_CHROMIUM_INTERNAL */ @@ -73,6 +74,7 @@ public: int Start(void); int Read(int size); void _Read(Waiter *sig, int size); + void SetError(int err_code); void OnResponseStarted(URLRequest *url_req, int net_error) override; void OnReadCompleted(URLRequest *url_req, int bytes_read) override; -- Ammar Faizi