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

Integrate review feedback

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