From: Radoslaw Zarzynski Date: Sat, 28 Jan 2017 19:17:10 +0000 (-0500) Subject: rgw: fix interface compliance of RGWCivetWeb::write_data() X-Git-Tag: v10.2.6~128^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F13169%2Fhead;p=ceph.git rgw: fix interface compliance of RGWCivetWeb::write_data() Backport of (portions of) civet web error handling bugfixes. Adapted from 3a9f50c55e0be6733893a7ae1a5b4f504a3b0f61. Signed-off-by: Matt Benjamin --- diff --git a/src/rgw/rgw_civetweb.cc b/src/rgw/rgw_civetweb.cc index d4a03e109d4b6..860c01bfadc5e 100644 --- a/src/rgw/rgw_civetweb.cc +++ b/src/rgw/rgw_civetweb.cc @@ -19,9 +19,11 @@ int RGWMongoose::write_data(const char *buf, int len) data.append(buf, len); return len; } - int r = mg_write(conn, buf, len); - if (r == 0) { - /* didn't send anything, error out */ + const int r = mg_write(conn, buf, len); + if (r <= 0) { + /* 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. */ return -EIO; } return r; @@ -36,7 +38,8 @@ RGWMongoose::RGWMongoose(mg_connection *_conn, int _port) int RGWMongoose::read_data(char *buf, int len) { - return mg_read(conn, buf, len); + const int ret = mg_read(conn, buf, len); + return (ret >= 0) ? ret : -EIO; } void RGWMongoose::flush()