From da595d309791e49d065761b1767cc8db289c985e Mon Sep 17 00:00:00 2001 From: Gabe Lee Date: Fri, 8 Nov 2019 10:00:11 +0800 Subject: [PATCH] rgw:[bug] civetweb mg_write with offset. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit data consistency error casued by rgw sent timeout. Incomplete data transmission and incorrect data re-transmission Signed-off-by: 李纲彬82225 <82225@sangfor.com> (cherry picked from commit d9fccedda90ff889fbaaa35ebacf3f3b4574ea09) --- src/rgw/rgw_civetweb.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rgw/rgw_civetweb.cc b/src/rgw/rgw_civetweb.cc index 1252835c624..f0f8ef5d1c0 100644 --- a/src/rgw/rgw_civetweb.cc +++ b/src/rgw/rgw_civetweb.cc @@ -15,15 +15,17 @@ size_t RGWCivetWeb::write_data(const char *buf, const size_t len) { + size_t off = 0; auto to_sent = len; while (to_sent) { - const int ret = mg_write(conn, buf, len); + const int ret = mg_write(conn, buf + off, to_sent); if (ret < 0 || ! ret) { /* According to the documentation of mg_write() it always returns -1 on * error. The details aren't available, so we will just throw EIO. Same * goes to 0 that is associated with writing to a closed connection. */ throw rgw::io::Exception(EIO, std::system_category()); } else { + off += static_cast(ret); to_sent -= static_cast(ret); } } -- 2.47.3