]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: fix interface compliance of RGWCivetWeb::write_data() 13169/head
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Sat, 28 Jan 2017 19:17:10 +0000 (14:17 -0500)
committerMatt Benjamin <mbenjamin@redhat.com>
Sat, 28 Jan 2017 19:17:10 +0000 (14:17 -0500)
Backport of (portions of) civet web error handling bugfixes.

Adapted from 3a9f50c55e0be6733893a7ae1a5b4f504a3b0f61.

Signed-off-by: Matt Benjamin <mbenjamin@redhat.com>
src/rgw/rgw_civetweb.cc

index d4a03e109d4b6675d1f0972a7fe1c385cee0460a..860c01bfadc5eed9f3bc1f003bfe594b2add3aab 100644 (file)
@@ -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()