Commit 4e522052 authored by Dominik Charousset's avatar Dominik Charousset

Integrate review feedback

Co-authored-by: default avatarJakob Otto <jakob.otto@haw-hamburg.de>
parent ab6f3b7f
...@@ -73,6 +73,11 @@ public: ...@@ -73,6 +73,11 @@ public:
bool handle_read_event(endpoint_manager&) override { bool handle_read_event(endpoint_manager&) override {
CAF_LOG_TRACE(CAF_ARG2("handle", this->handle().id)); CAF_LOG_TRACE(CAF_ARG2("handle", this->handle().id));
auto fail = [this](sec err) {
CAF_LOG_DEBUG("read failed" << CAF_ARG(err));
this->next_layer_.handle_error(err);
return false;
};
for (size_t reads = 0; reads < this->max_consecutive_reads_; ++reads) { for (size_t reads = 0; reads < this->max_consecutive_reads_; ++reads) {
auto buf = this->read_buf_.data() + collected_; auto buf = this->read_buf_.data() + collected_;
size_t len = read_threshold_ - collected_; size_t len = read_threshold_ - collected_;
...@@ -91,16 +96,16 @@ public: ...@@ -91,16 +96,16 @@ public:
} }
this->prepare_next_read(); this->prepare_next_read();
} }
} else if (num_bytes == 0) { } else if (num_bytes < 0) {
auto err = sec::socket_disconnected; // Try again later on temporary errors such as EWOULDBLOCK and
CAF_LOG_DEBUG("read failed" << CAF_ARG(err)); // stop reading on the socket on hard errors.
this->next_layer_.handle_error(err); return last_socket_error_is_temporary()
return false; ? true
} else if (!last_socket_error_is_temporary()) { : fail(sec::socket_operation_failed);
auto err = sec::socket_operation_failed;
CAF_LOG_DEBUG("read failed" << CAF_ARG(err)); } else {
this->next_layer_.handle_error(err); // read() returns 0 iff the connection was closed.
return false; return fail(sec::socket_disconnected);
} }
} }
return true; return true;
...@@ -126,6 +131,11 @@ public: ...@@ -126,6 +131,11 @@ public:
} }
write_queue_.pop_front(); write_queue_.pop_front();
}; };
auto fail = [this](sec err) {
CAF_LOG_DEBUG("write failed" << CAF_ARG(err));
this->next_layer_.handle_error(err);
return err;
};
// Write buffers from the write_queue_ for as long as possible. // Write buffers from the write_queue_ for as long as possible.
while (!write_queue_.empty()) { while (!write_queue_.empty()) {
auto& buf = write_queue_.front().second; auto& buf = write_queue_.front().second;
...@@ -140,16 +150,14 @@ public: ...@@ -140,16 +150,14 @@ public:
recycle(); recycle();
written_ = 0; written_ = 0;
} }
} else if (num_bytes == 0) { } else if (num_bytes < 0) {
auto err = sec::socket_disconnected; return last_socket_error_is_temporary()
CAF_LOG_DEBUG("send failed" << CAF_ARG(err)); ? sec::unavailable_or_would_block
this->next_layer_.handle_error(err); : fail(sec::socket_operation_failed);
return err;
} else if (!last_socket_error_is_temporary()) { } else {
auto err = sec::socket_operation_failed; // write() returns 0 iff the connection was closed.
CAF_LOG_DEBUG("send failed" << CAF_ARG(err)); return fail(sec::socket_disconnected);
this->next_layer_.handle_error(err);
return err;
} }
} }
return none; return none;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment