| 393 | } |
| 394 | |
| 395 | std::tuple<bool, std::string> |
| 396 | IPCSocketServer::Client::read_all(Buffer &bw) const |
| 397 | { |
| 398 | std::string buff; |
| 399 | while (true) { |
| 400 | auto ret = read({bw.writable_data(), bw.available()}); |
| 401 | if (ret < 0) { |
| 402 | if (check_for_transient_errors()) { |
| 403 | continue; |
| 404 | } else { |
| 405 | return {false, swoc::bwprint(buff, "Error reading the socket: {}", swoc::bwf::Errno{})}; |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | if (ret == 0) { |
| 410 | if (bw.stored()) { |
| 411 | return {false, swoc::bwprint(buff, "Peer disconnected after reading {} bytes.", bw.stored())}; |
| 412 | } |
| 413 | return {false, swoc::bwprint(buff, "Peer disconnected. EOF")}; |
| 414 | } |
| 415 | bw.save(ret); |
| 416 | if (_max_req_size - bw.stored() > 0) { // we can still read more. |
| 417 | using namespace std::chrono_literals; |
| 418 | if (!this->poll_for_data(1ms)) { |
| 419 | return {true, buff}; |
| 420 | } |
| 421 | continue; |
| 422 | } else { |
| 423 | swoc::bwprint(buff, "Buffer is full, we hit the limit: {}", _max_req_size); |
| 424 | break; |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | return {false, buff}; |
| 429 | } |
| 430 | |
| 431 | void |
| 432 | IPCSocketServer::Client::write(std::string const &data, std::error_code &ec) const |