AsyncBerkeley
Asynchronous Berkeley sockets. Simple.
Loading...
Searching...
No Matches
concepts.hpp
Go to the documentation of this file.
1/* Copyright 2025 Kevin Exton
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
20#pragma once
21#ifndef IO_CONCEPTS_HPP
22#define IO_CONCEPTS_HPP
23#include "io/config.h"
24#if OS_WINDOWS
25#else
26#include "platforms/posix/concepts_posix.hpp" // IWYU pragma: export
27#endif
28#include "io/socket/detail/socket.hpp"
29
30#include <memory>
31#include <optional>
32#include <type_traits>
33// Forward declarations
34namespace io {
35namespace socket {
36class socket_handle;
37} // namespace socket
38namespace execution {
39enum struct execution_trigger : std::uint8_t;
40} // namespace execution
41} // namespace io
42
47namespace io {
48
50template <typename Allocator>
52 requires(Allocator alloc, typename Allocator::value_type *ptr) {
53 { alloc.allocate(0) } -> std::same_as<decltype(ptr)>;
54 { alloc.deallocate(ptr, 0) } -> std::same_as<void>;
55 };
56
58template <typename B>
59concept ScatterGatherLike = requires(B buf) {
60 std::ranges::data(buf);
61 std::ranges::size(buf);
62};
63
72template <typename T>
73concept MuxTag = requires(T tag) {
74 typename T::event_type;
75 typename T::interval_type;
76 typename T::size_type;
77 typename T::template is_eager_t<T>;
78 T::template is_eager_v<T>;
79};
80
85template <typename Fn>
86concept Completion = requires(Fn &&func) {
87 requires std::is_invocable_v<Fn>;
88 typename std::invoke_result_t<Fn>::value_type;
89 requires std::is_same_v<
90 std::invoke_result_t<Fn>,
91 std::optional<typename std::invoke_result_t<Fn>::value_type>>;
92};
93
102template <typename T>
103concept Multiplexer = requires(T mux) {
104 requires MuxTag<T>;
105 typename T::demultiplexer;
106 typename T::template sender<decltype([]() -> std::optional<int> {
107 return std::nullopt;
108 })>;
109 mux.set(std::shared_ptr<socket::socket_handle>{},
110 execution::execution_trigger{},
111 []() -> std::optional<int> { return std::nullopt; });
112 mux.wait_for(typename T::interval_type{});
113};
114
119template <typename Socket>
120concept SocketLike = requires {
121 requires std::is_constructible_v<Socket, socket::native_socket_type>;
122 static_cast<socket::native_socket_type>(Socket{});
123};
124
129template <typename Dialog>
130concept DialogLike = requires(Dialog &dialog) {
131 typename Dialog::executor_type;
132 dialog.executor;
133 dialog.socket;
134};
135
140template <typename Message>
141concept MessageLike =
142 requires(Message msg) { static_cast<socket::socket_message_type>(msg); };
143
144} // namespace io
145#endif // IO_CONCEPTS_HPP
A concept that checks if a type is an allocator.
Definition concepts.hpp:51
Concept for a completion handler.
Definition concepts.hpp:86
Concept for types that behave like a dialog.
Definition concepts.hpp:130
Concept for types that behave like a socket message.
Definition concepts.hpp:141
Concept for a multiplexer.
Definition concepts.hpp:103
Concept for a multiplexer tag.
Definition concepts.hpp:73
A concept that describes a scatter/gather like buffer object.
Definition concepts.hpp:59
Concept for types that behave like a socket.
Definition concepts.hpp:120
This file defines various macros that configure AsyncBerkeley.
The io namespace contains all the functions and classes for the I/O library.
Definition executor.hpp:33