Commit 98d8117d authored by Dominik Charousset's avatar Dominik Charousset

Clean up naming and style nitpicks

parent 7267d945
...@@ -14,8 +14,8 @@ enum class rw_state { ...@@ -14,8 +14,8 @@ enum class rw_state {
failure, failure,
/// Reports that an empty buffer is in use and no operation was performed. /// Reports that an empty buffer is in use and no operation was performed.
indeterminate, indeterminate,
/// Reports an ssl error: ssl_error_want_read /// Reports that the transport wants to read data before it can write again.
ssl_error_want_read want_read
}; };
} // namespace caf::io::network } // namespace caf::io::network
...@@ -144,13 +144,12 @@ bool stream::handle_read_result(rw_state read_result, size_t rb) { ...@@ -144,13 +144,12 @@ bool stream::handle_read_result(rw_state read_result, size_t rb) {
case rw_state::indeterminate: case rw_state::indeterminate:
return false; return false;
case rw_state::success: case rw_state::success:
// if it is the first rw_state::success after SSL_connect, // Recover previous pending write if it is the first successful read after
// the ssl connection is established. We recover previous pending write OP. // want_read was reported.
if(wr_op_backoff_) { if (wr_op_backoff_) {
backend().add(operation::write, fd(), this); backend().add(operation::write, fd(), this);
wr_op_backoff_ = false; wr_op_backoff_ = false;
} }
case rw_state::ssl_error_want_read:
if (rb == 0) if (rb == 0)
return false; return false;
collected_ += rb; collected_ += rb;
...@@ -163,6 +162,9 @@ bool stream::handle_read_result(rw_state read_result, size_t rb) { ...@@ -163,6 +162,9 @@ bool stream::handle_read_result(rw_state read_result, size_t rb) {
} }
} }
break; break;
case rw_state::want_read:
CAF_LOG_ERROR("handle_read_result encountered rw_state::want_read");
return false;
} }
return true; return true;
} }
...@@ -176,13 +178,15 @@ void stream::handle_write_result(rw_state write_result, size_t wb) { ...@@ -176,13 +178,15 @@ void stream::handle_write_result(rw_state write_result, size_t wb) {
case rw_state::indeterminate: case rw_state::indeterminate:
prepare_next_write(); prepare_next_write();
break; break;
case rw_state::ssl_error_want_read: case rw_state::want_read:
// if write op returns ssl_error_want_read, don't write until SSL connection is established. // If the write operation returns want_read, we need to suspend writing to
// otherwise, any write OP will get ssl_error_want_read immediately, causing spinning and high CPU usage. // the socket until the next successful read. Otherwise, we may cause
// spinning and high CPU usage.
backend().del(operation::write, fd(), this); backend().del(operation::write, fd(), this);
wr_op_backoff_ = true; wr_op_backoff_ = true;
if(wb == 0) if (wb == 0)
break; break;
[[fallthrough]];
case rw_state::success: case rw_state::success:
written_ += wb; written_ += wb;
CAF_ASSERT(written_ <= wr_buf_.size()); CAF_ASSERT(written_ <= wr_buf_.size());
......
...@@ -94,7 +94,7 @@ rw_state session::do_some(int (*f)(SSL*, void*, int), size_t& result, void* buf, ...@@ -94,7 +94,7 @@ rw_state session::do_some(int (*f)(SSL*, void*, int), size_t& result, void* buf,
return rw_state::failure; return rw_state::failure;
case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_READ:
CAF_LOG_DEBUG("SSL_ERROR_WANT_READ reported"); CAF_LOG_DEBUG("SSL_ERROR_WANT_READ reported");
return rw_state::ssl_error_want_read; return rw_state::want_read;
case SSL_ERROR_WANT_WRITE: case SSL_ERROR_WANT_WRITE:
CAF_LOG_DEBUG("SSL_ERROR_WANT_WRITE reported"); CAF_LOG_DEBUG("SSL_ERROR_WANT_WRITE reported");
// Report success to poll on this socket. // Report success to poll on this socket.
......
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