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

Integrate review feedback

parent dbc51213
...@@ -52,18 +52,18 @@ public: ...@@ -52,18 +52,18 @@ public:
return handle_; return handle_;
} }
/// Returns for which operations the socket is registered (read or write). /// Returns registered operations (read, write, or both).
operation mask() const noexcept; operation mask() const noexcept;
/// Adds given flag(s) to the event mask and updates the parent on success. /// Adds given flag(s) to the event mask and updates the parent on success.
/// @returns `false` if `mask()` already contained `flag`, `true` otherwise. /// @returns `false` if `mask() | flag == mask()`, `true` otherwise.
/// @pre `has_parent()` /// @pre `has_parent()`
/// @pre `flag != operation::none` /// @pre `flag != operation::none`
bool mask_add(operation flag) noexcept; bool mask_add(operation flag) noexcept;
/// Deletes given flag(s) from the event mask and updates the parent on /// Deletes given flag(s) from the event mask and updates the parent on
/// success. /// success.
/// @returns `false` if `mask()` already missed `flag`, `true` otherwise. /// @returns `false` if `mask() & ~flag == mask()`, `true` otherwise.
/// @pre `has_parent()` /// @pre `has_parent()`
/// @pre `flag != operation::none` /// @pre `flag != operation::none`
bool mask_del(operation flag) noexcept; bool mask_del(operation flag) noexcept;
...@@ -73,7 +73,7 @@ public: ...@@ -73,7 +73,7 @@ public:
/// Called whenever the socket received new data. /// Called whenever the socket received new data.
virtual bool handle_read_event() = 0; virtual bool handle_read_event() = 0;
/// Called whenever the socket is allowed to send additional data. /// Called whenever the socket is allowed to send data.
virtual bool handle_write_event() = 0; virtual bool handle_write_event() = 0;
/// Called when the remote side becomes unreachable due to an error. /// Called when the remote side becomes unreachable due to an error.
......
...@@ -59,7 +59,7 @@ error nodelay(stream_socket x, bool new_value); ...@@ -59,7 +59,7 @@ error nodelay(stream_socket x, bool new_value);
/// @param buf_size Specifies the maximum size of the buffer in bytes. /// @param buf_size Specifies the maximum size of the buffer in bytes.
/// @returns The number of received bytes on success, an error code otherwise. /// @returns The number of received bytes on success, an error code otherwise.
/// @relates pipe_socket /// @relates pipe_socket
/// @post either the result is a `sec` or a positive (non-zero) integer. /// @post either the result is a `sec` or a positive (non-zero) integer
variant<size_t, sec> read(stream_socket x, void* buf, size_t buf_size); variant<size_t, sec> read(stream_socket x, void* buf, size_t buf_size);
/// Transmits data from `x` to its peer. /// Transmits data from `x` to its peer.
...@@ -68,7 +68,7 @@ variant<size_t, sec> read(stream_socket x, void* buf, size_t buf_size); ...@@ -68,7 +68,7 @@ variant<size_t, sec> read(stream_socket x, void* buf, size_t buf_size);
/// @param buf_size Specifies the size of the buffer in bytes. /// @param buf_size Specifies the size of the buffer in bytes.
/// @returns The number of written bytes on success, otherwise an error code. /// @returns The number of written bytes on success, otherwise an error code.
/// @relates pipe_socket /// @relates pipe_socket
/// @post either the result is a `sec` or a positive (non-zero) integer. /// @post either the result is a `sec` or a positive (non-zero) integer
variant<size_t, sec> write(stream_socket x, const void* buf, size_t buf_size); variant<size_t, sec> write(stream_socket x, const void* buf, size_t buf_size);
} // namespace net } // namespace net
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#include "caf/net/multiplexer.hpp" #include "caf/net/multiplexer.hpp"
#include <algorithm>
#include "caf/config.hpp" #include "caf/config.hpp"
#include "caf/error.hpp" #include "caf/error.hpp"
#include "caf/expected.hpp" #include "caf/expected.hpp"
...@@ -97,11 +99,10 @@ size_t multiplexer::num_socket_managers() const noexcept { ...@@ -97,11 +99,10 @@ size_t multiplexer::num_socket_managers() const noexcept {
} }
ptrdiff_t multiplexer::index_of(const socket_manager_ptr& mgr) { ptrdiff_t multiplexer::index_of(const socket_manager_ptr& mgr) {
auto max_index = static_cast<ptrdiff_t>(managers_.size()); auto first = managers_.begin();
for (ptrdiff_t index = 0; index < max_index; ++index) auto last = managers_.end();
if (managers_[index] == mgr) auto i = std::find(first, last, mgr);
return index; return i == last ? -1 : std::distance(first, i);
return -1;
} }
void multiplexer::update(const socket_manager_ptr& mgr) { void multiplexer::update(const socket_manager_ptr& mgr) {
......
...@@ -29,6 +29,7 @@ pollset_updater::pollset_updater(pipe_socket read_handle, ...@@ -29,6 +29,7 @@ pollset_updater::pollset_updater(pipe_socket read_handle,
multiplexer_ptr parent) multiplexer_ptr parent)
: super(read_handle, std::move(parent)) { : super(read_handle, std::move(parent)) {
mask_ = operation::read; mask_ = operation::read;
nonblocking(read_handle, true);
} }
pollset_updater::~pollset_updater() { pollset_updater::~pollset_updater() {
...@@ -44,8 +45,9 @@ bool pollset_updater::handle_read_event() { ...@@ -44,8 +45,9 @@ bool pollset_updater::handle_read_event() {
socket_manager_ptr mgr{reinterpret_cast<socket_manager*>(value), false}; socket_manager_ptr mgr{reinterpret_cast<socket_manager*>(value), false};
if (auto ptr = parent_.lock()) if (auto ptr = parent_.lock())
ptr->update(mgr); ptr->update(mgr);
} else {
return get<sec>(res) == sec::unavailable_or_would_block;
} }
return get<sec>(res) == sec::unavailable_or_would_block;
} }
} }
......
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