- const int ret = mg_read(conn, buf, len);
- if (ret < 0) {
- throw rgw::io::Exception(EIO, std::system_category());
+ int c, ret;
+ if (got_eof_on_read) {
+ return 0;
+ }
+ for (c = 0; c < len; c += ret) {
+ ret = mg_read(conn, buf, len);
+ if (ret < 0) {
+ throw rgw::io::Exception(EIO, std::system_category());
+ }
+ if (!ret) {
+ got_eof_on_read = true;
+ break;
+ }