OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
socket.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_H_
7#define OPENCBDC_TX_SRC_NETWORK_SOCKET_H_
8
9#include <memory>
10#include <netdb.h>
11#include <string>
12
13namespace cbdc::network {
15 using ip_address = std::string;
17 using port_number_t = unsigned short;
19 using endpoint_t = std::pair<ip_address, port_number_t>;
20
22 static const auto localhost = ip_address("127.0.0.1");
23
30 class socket {
31 public:
32 socket(const socket&) = delete;
33 auto operator=(const socket&) -> socket& = delete;
34
35 socket(socket&&) = delete;
36 auto operator=(socket&&) -> socket& = delete;
37
38 virtual ~socket() = default;
39
40 private:
41 socket();
42
43 int m_sock_fd{-1};
44
45 friend class tcp_socket;
46 friend class tcp_listener;
47 friend class socket_selector;
48
49 static auto get_addrinfo(const ip_address& address, port_number_t port)
50 -> std::shared_ptr<addrinfo>;
51
52 virtual auto create_socket(int domain, int type, int protocol) -> bool;
53 virtual auto set_sockopts() -> bool;
54 };
55}
56
57#endif
Waits on a group of blocking sockets to be ready for read operations.
Generic superclass for network sockets.
Definition socket.hpp:30
auto operator=(const socket &) -> socket &=delete
auto operator=(socket &&) -> socket &=delete
socket(const socket &)=delete
virtual ~socket()=default
socket(socket &&)=delete
Listens for incoming TCP connections on a given endpoint.
Wrapper for a TCP socket.
std::string ip_address
An IP addresses.
Definition socket.hpp:15
std::pair< ip_address, port_number_t > endpoint_t
[host name, port number].
Definition socket.hpp:19
unsigned short port_number_t
Port number.
Definition socket.hpp:17