1 #ifndef UVW_TCP_INCLUDE_H
2 #define UVW_TCP_INCLUDE_H
11 #include "request.hpp"
22 enum class UVTCPFlags: std::underlying_type_t<uv_tcp_flags> {
23 IPV6ONLY = UV_TCP_IPV6ONLY
48 using Time = std::chrono::duration<unsigned int>;
49 using Bind = details::UVTCPFlags;
53 explicit TCPHandle(ConstructorAccess ca, std::shared_ptr<Loop> ref,
unsigned int f = {});
85 bool keepAlive(
bool enable =
false, Time time = Time{0});
138 template<
typename I = IPv4>
157 template<
typename I = IPv4>
164 template<
typename I = IPv4>
171 template<typename I =
IPv4>
199 template<typename I =
IPv4>
200 void connect(const std::
string &ip,
unsigned int port);
211 template<typename I =
IPv4>
228 enum { DEFAULT, FLAGS } tag;
241 extern template void TCPHandle::bind<IPv4>(
const std::string &,
unsigned int, Flags<Bind>);
242 extern template void TCPHandle::bind<IPv6>(
const std::string &,
unsigned int, Flags<Bind>);
244 extern template void TCPHandle::bind<IPv4>(Addr, Flags<Bind>);
245 extern template void TCPHandle::bind<IPv6>(Addr, Flags<Bind>);
247 extern template Addr TCPHandle::sock<IPv4>() const noexcept;
248 extern template Addr TCPHandle::sock<IPv6>() const noexcept;
250 extern template Addr TCPHandle::peer<IPv4>() const noexcept;
251 extern template Addr TCPHandle::peer<IPv6>() const noexcept;
253 extern template
void TCPHandle::connect<IPv4>(const std::
string &,
unsigned int);
254 extern template
void TCPHandle::connect<IPv6>(const std::
string &,
unsigned int);
256 extern template
void TCPHandle::connect<IPv4>(Addr addr);
257 extern template
void TCPHandle::connect<IPv6>(Addr addr);
Utility class to handle flags.
bool init()
Initializes the handle. No socket is created as of yet.
Addr sock() const noexcept
Gets the current address to which the handle is bound.
void closeReset()
Resets a TCP connection by sending a RST packet.
void open(OSSocketHandle socket)
Opens an existing file descriptor or SOCKET as a TCP handle.
bool keepAlive(bool enable=false, Time time=Time{0})
Enables/Disables TCP keep-alive.
bool noDelay(bool value=false)
Enables/Disables Nagle’s algorithm.
Addr peer() const noexcept
Gets the address of the peer connected to the handle.
bool simultaneousAccepts(bool enable=true)
Enables/Disables simultaneous asynchronous accept requests.
void bind(const std::string &ip, unsigned int port, Flags< Bind > opts=Flags< Bind >{})
Binds the handle to an address and port.
void bind(Addr addr, Flags< Bind > opts=Flags< Bind >{})
Binds the handle to an address and port.
void connect(const sockaddr &addr)
Establishes an IPv4 or IPv6 TCP connection.
void bind(const sockaddr &addr, Flags< Bind > opts=Flags< Bind >{})
Binds the handle to an address and port.
details::UVTypeWrapper< uv_os_sock_t > OSSocketHandle