int64_t readAtMost(ServerSocket &s, char *buf, int64_t max, int64_t atMost) { const int64_t target = atMost < max ? atMost : max; VLOG(3) << "readAtMost target " << target; // because we want to process data as soon as it arrives, tryFull option for // read is false int64_t n = s.read(buf, target, false); if (n < 0) { PLOG(ERROR) << "Read error on " << s.getPort() << " with target " << target; return n; } if (n == 0) { LOG(WARNING) << "Eof on " << s.getFd(); return n; } VLOG(3) << "readAtMost " << n << " / " << atMost << " from " << s.getFd(); return n; }