Commit 240bb073 authored by Dominik Charousset's avatar Dominik Charousset

Integrate review feedback

parent fb51d49b
......@@ -23,6 +23,7 @@
#include <type_traits>
#include "caf/config.hpp"
#include "caf/detail/comparable.hpp"
#include "caf/fwd.hpp"
#include "caf/net/socket_id.hpp"
......@@ -31,24 +32,24 @@ namespace net {
/// An internal endpoint for sending or receiving data. Can be either a
/// ::network_socket, ::pipe_socket, ::stream_socket, or ::datagram_socket.
struct socket {
struct socket : detail::comparable<socket> {
socket_id id;
constexpr socket() : id(invalid_socket_id) {
constexpr socket() noexcept : id(invalid_socket_id) {
// nop
}
constexpr explicit socket(socket_id id) : id(id) {
constexpr explicit socket(socket_id id) noexcept : id(id) {
// nop
}
constexpr socket(const socket& other) : id(other.id) {
// nop
}
constexpr socket(const socket& other) noexcept = default;
socket& operator=(const socket& other) noexcept = default;
socket& operator=(const socket& other) {
id = other.id;
return *this;
constexpr signed_socket_id compare(socket other) const noexcept {
return static_cast<signed_socket_id>(id)
- static_cast<signed_socket_id>(other.id);
}
};
......@@ -58,21 +59,6 @@ typename Inspector::result_type inspect(Inspector& f, socket& x) {
return f(x.id);
}
/// @relates socket
constexpr bool operator==(socket x, socket y) {
return x.id == y.id;
}
/// @relates socket
constexpr bool operator!=(socket x, socket y) {
return x.id != y.id;
}
/// @relates socket
constexpr bool operator<(socket x, socket y) {
return x.id < y.id;
}
/// Denotes the invalid socket.
constexpr auto invalid_socket = socket{invalid_socket_id};
......
......@@ -20,6 +20,7 @@
#include <cstddef>
#include <limits>
#include <type_traits>
#include "caf/config.hpp"
......@@ -46,5 +47,9 @@ constexpr socket_id invalid_socket_id = -1;
#endif // CAF_WINDOWS
/// Signed counterpart of `socket_id`.
/// @relates socket
using signed_socket_id = std::make_signed<socket_id>::type;
} // namespace net
} // namespace caf
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