OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
socket_selector.hpp
Go to the documentation of this file.
1// Copyright (c) 2021 MIT Digital Currency Initiative,
2// Federal Reserve Bank of Boston
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef OPENCBDC_TX_SRC_NETWORK_SOCKET_SELECTOR_H_
7#define OPENCBDC_TX_SRC_NETWORK_SOCKET_SELECTOR_H_
8
9#include "socket.hpp"
10
11#include <array>
12
13namespace cbdc::network {
22 public:
24 socket_selector() = default;
27 auto operator=(const socket_selector&) -> socket_selector& = delete;
30
34 auto init() -> bool;
35
40 auto add(const socket& sock) -> bool;
41
45 auto wait() -> bool;
46
48 void unblock();
49
50 private:
51 fd_set m_fds{};
52 fd_set m_ready_fds{};
53 int m_fd_max{-1};
54 std::array<int, 2> m_unblock_fds{-1, -1};
55
56 auto add(int fd) -> bool;
57 };
58}
59
60#endif
Waits on a group of blocking sockets to be ready for read operations.
socket_selector()=default
Constructs an empty socket selector.
socket_selector(const socket_selector &)=delete
auto operator=(socket_selector &&) -> socket_selector &=delete
socket_selector(socket_selector &&)=delete
auto add(const socket &sock) -> bool
Adds a socket to the selector so that it is checked for events after a call to wait.
auto wait() -> bool
Blocks until at least one socket in the selector is ready to perform a read operation.
void unblock()
Unblocks a blocked wait() call.
auto init() -> bool
Sets-up the socket selector.
auto operator=(const socket_selector &) -> socket_selector &=delete
Generic superclass for network sockets.
Definition socket.hpp:30