uvw 3.1.0
Loading...
Searching...
No Matches
tcp.h
1#ifndef UVW_TCP_INCLUDE_H
2#define UVW_TCP_INCLUDE_H
3
4#include <chrono>
5#include <memory>
6#include <string>
7#include <type_traits>
8#include <utility>
9#include <uv.h>
10#include "config.h"
11#include "enum.hpp"
12#include "request.hpp"
13#include "stream.h"
14#include "util.h"
15
16namespace uvw {
17
18namespace details {
19
20enum class uvw_tcp_flags : std::underlying_type_t<uv_tcp_flags> {
21 IPV6ONLY = UV_TCP_IPV6ONLY,
22 _UVW_ENUM = 0
23};
24
25}
26
43class tcp_handle final: public stream_handle<tcp_handle, uv_tcp_t> {
44public:
45 using time = std::chrono::duration<unsigned int>;
46 using tcp_flags = details::uvw_tcp_flags;
47 using ipv4 = uvw::ipv4;
48 using ipv6 = uvw::ipv6;
49
50 explicit tcp_handle(loop::token token, std::shared_ptr<loop> ref, unsigned int f = {});
51
56 int init() final;
57
70
76 bool no_delay(bool value = false);
77
85 bool keep_alive(bool enable = false, time val = time{0});
86
101 bool simultaneous_accepts(bool enable = true);
102
118 int bind(const sockaddr &addr, tcp_flags opts = tcp_flags::_UVW_ENUM);
119
136 int bind(const std::string &ip, unsigned int port, tcp_flags opts = tcp_flags::_UVW_ENUM);
137
153 int bind(socket_address addr, tcp_flags opts = tcp_flags::_UVW_ENUM);
154
160 socket_address sock() const noexcept;
161
167 socket_address peer() const noexcept;
168
181 int connect(const sockaddr &addr);
182
192 int connect(const std::string &ip, unsigned int port);
193
203
217
218private:
219 enum {
220 DEFAULT,
221 FLAGS
222 } tag;
223
224 unsigned int flags;
225};
226
227} // namespace uvw
228
229#ifndef UVW_AS_LIB
230# include "tcp.cpp"
231#endif
232
233#endif // UVW_TCP_INCLUDE_H
The stream handle.
Definition: stream.h:108
The TCP handle.
Definition: tcp.h:43
bool keep_alive(bool enable=false, time val=time{0})
Enables/Disables TCP keep-alive.
int init() final
Initializes the handle. No socket is created as of yet.
int bind(const sockaddr &addr, tcp_flags opts=tcp_flags::_UVW_ENUM)
Binds the handle to an address and port.
int bind(const std::string &ip, unsigned int port, tcp_flags opts=tcp_flags::_UVW_ENUM)
Binds the handle to an address and port.
int connect(const sockaddr &addr)
Establishes an IPv4 or IPv6 TCP connection.
int close_reset()
Resets a TCP connection by sending a RST packet.
int open(os_socket_handle socket)
Opens an existing file descriptor or SOCKET as a TCP handle.
bool simultaneous_accepts(bool enable=true)
Enables/Disables simultaneous asynchronous accept requests.
bool no_delay(bool value=false)
Enables/Disables Nagle’s algorithm.
socket_address peer() const noexcept
Gets the address of the peer connected to the handle.
socket_address sock() const noexcept
Gets the current address to which the handle is bound.
int bind(socket_address addr, tcp_flags opts=tcp_flags::_UVW_ENUM)
Binds the handle to an address and port.
uvw default namespace.
Definition: async.h:8
details::uv_type_wrapper< uv_os_sock_t > os_socket_handle
Definition: util.h:86
The IPv4 tag.
Definition: util.h:202
The IPv6 tag.
Definition: util.h:209
Address representation.
Definition: util.h:214