qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
socket.h
Go to the documentation of this file.
1
24
25#include "../system/sys__socket.h"
26#include "../uri.h"
27
28#ifndef QB_IO_TCP_SOCKET_H_
29#define QB_IO_TCP_SOCKET_H_
30
31namespace qb::io::tcp {
32
43class QB_API socket : protected qb::io::socket {
52 int connect_in(int af, std::string const &host, uint16_t port) noexcept;
53
62 int n_connect_in(int af, std::string const &host, uint16_t port) noexcept;
63
64public:
65 // Methods inherited from the base socket (made public via using-declarations)
66 using qb::io::socket::close;
67 using qb::io::socket::get_optval;
68 using qb::io::socket::is_open;
69 using qb::io::socket::local_endpoint;
70 using qb::io::socket::native_handle;
71 using qb::io::socket::peer_endpoint;
72 using qb::io::socket::release_handle;
73 using qb::io::socket::set_nonblocking;
74 using qb::io::socket::set_optval;
75 using qb::io::socket::test_nonblocking;
76
78 constexpr static bool is_secure() noexcept { return false; }
83 socket() = default;
84
88 socket(socket const &) = delete;
89
93 socket(socket &&) = default;
94
99 socket &operator=(socket &&) = default;
100
106 socket(io::socket &&sock) noexcept;
107
113 socket &operator=(io::socket &&sock) noexcept;
114
121 int init(int af = AF_INET) noexcept;
122
129 int bind(qb::io::endpoint const &ep) noexcept;
130
136 int bind(qb::io::uri const &u) noexcept;
137
144 int connect(qb::io::endpoint const &ep) noexcept;
145
151 int connect(uri const &u) noexcept;
152
159 int connect_v4(std::string const &host, uint16_t port) noexcept;
160
167 int connect_v6(std::string const &host, uint16_t port) noexcept;
168
175 int connect_un(std::string const &path) noexcept;
176
186 int n_connect(qb::io::endpoint const &ep) noexcept;
187
193 inline void
194 connected() noexcept {}
195
201 int n_connect(uri const &u) noexcept;
202
209 int n_connect_v4(std::string const &host, uint16_t port) noexcept;
210
217 int n_connect_v6(std::string const &host, uint16_t port) noexcept;
218
224 int n_connect_un(std::string const &path) noexcept;
225
234 int read(void *dest, std::size_t len) const noexcept;
235
244 int write(const void *data, std::size_t size) const noexcept;
245
251 int disconnect() const noexcept;
252};
253
254} // namespace qb::io::tcp
255
256#endif // QB_IO_TCP_SOCKET_H_
int bind(qb::io::endpoint const &ep) noexcept
Bind the socket to a specific local endpoint.
int n_connect_v4(std::string const &host, uint16_t port) noexcept
Initiate a non-blocking connect to an IPv4 TCP server.
int bind(qb::io::uri const &u) noexcept
Bind the socket to an endpoint specified by a URI.
int connect(qb::io::endpoint const &ep) noexcept
Connect to a remote TCP endpoint.
void connected() noexcept
Called after a non-blocking connect attempt succeeds or needs to be finalized.
Definition socket.h:194
int n_connect_un(std::string const &path) noexcept
Initiate a non-blocking connect to a Unix domain TCP-style socket.
int connect_un(std::string const &path) noexcept
Connect to a Unix domain TCP-style socket.
int read(void *dest, std::size_t len) const noexcept
Read data from the connected TCP socket.
socket(socket &&)=default
Default move constructor.
int n_connect(qb::io::endpoint const &ep) noexcept
Initiate a non-blocking connect to a remote TCP endpoint.
int disconnect() const noexcept
Disconnect the TCP socket.
int n_connect_v6(std::string const &host, uint16_t port) noexcept
Initiate a non-blocking connect to an IPv6 TCP server.
socket & operator=(socket &&)=default
Default move assignment operator.
int connect_v4(std::string const &host, uint16_t port) noexcept
Connect to an IPv4 TCP server.
socket()=default
Default constructor.
socket(io::socket &&sock) noexcept
Constructor from a generic qb::io::socket (move semantics).
static constexpr bool is_secure() noexcept
Indicates that this socket implementation is not secure.
Definition socket.h:78
int connect_v6(std::string const &host, uint16_t port) noexcept
Connect to an IPv6 TCP server.
int init(int af=AF_INET) noexcept
Initialize (open) the TCP socket.
int connect(uri const &u) noexcept
Connect to a remote TCP endpoint specified by a URI.
int n_connect(uri const &u) noexcept
Initiate a non-blocking connect to a remote TCP endpoint specified by a URI.
socket(socket const &)=delete
Deleted copy constructor.
socket & operator=(io::socket &&sock) noexcept
Move assignment operator from a generic qb::io::socket.
int write(const void *data, std::size_t size) const noexcept
Write data to the connected TCP socket.
Class for parsing, manipulating, and representing URIs.
Definition uri.h:181
URI parsing and manipulation utilities.