minor changes
This commit is contained in:
parent
513f5264cb
commit
dfd347b5f7
@ -195,8 +195,8 @@ tcp->bind("127.0.0.1", 4242);
|
||||
tcp->listen();
|
||||
```
|
||||
|
||||
Note also that `uvw::TcpHandle` already supports _IPv6_ out-of-the-box. The statement above is equivalent to `tcp->bind<uvw::TcpHandle::IPv4>("127.0.0.1", 4242)`.<br/>
|
||||
It's suffice to explicitly specify `uvw::TcpHandle::IPv6` as the underlying protocol to use it.
|
||||
Note also that `uvw::TcpHandle` already supports _IPv6_ out-of-the-box. The statement above is equivalent to `tcp->bind<uvw::net::IPv4>("127.0.0.1", 4242)`.<br/>
|
||||
It's suffice to explicitly specify `uvw::net::IPv6` as the underlying protocol to use it.
|
||||
|
||||
The API reference is the recommended documentation for further details about resources and their methods.
|
||||
|
||||
|
||||
@ -198,9 +198,6 @@ class GetNameInfoReq final: public Request<GetNameInfoReq, uv_getnameinfo_t> {
|
||||
using Request::Request;
|
||||
|
||||
public:
|
||||
using IPv4 = details::IPv4;
|
||||
using IPv6 = details::IPv6;
|
||||
|
||||
/**
|
||||
* @brief Creates a new `getnameinfo` wrapper request.
|
||||
* @param args A pointer to the loop from which the handle generated.
|
||||
@ -217,7 +214,7 @@ public:
|
||||
* @param port A valid port number.
|
||||
* @param flags Optional flags that modify the behavior of `getnameinfo`.
|
||||
*/
|
||||
template<typename I = IPv4>
|
||||
template<typename I = net::IPv4>
|
||||
void getNameInfo(std::string ip, unsigned int port, int flags = 0) {
|
||||
typename details::IpTraits<I>::Type addr;
|
||||
details::IpTraits<I>::AddrFunc(ip.data(), port, &addr);
|
||||
@ -229,7 +226,7 @@ public:
|
||||
* @param addr A valid instance of Addr.
|
||||
* @param flags Optional flags that modify the behavior of `getnameinfo`.
|
||||
*/
|
||||
template<typename I = IPv4>
|
||||
template<typename I = net::IPv4>
|
||||
void getNameInfo(Addr addr, int flags = 0) {
|
||||
getNameInfo<I>(addr.ip, addr.port, flags);
|
||||
}
|
||||
@ -240,7 +237,7 @@ public:
|
||||
* @param port A valid port number.
|
||||
* @param flags Optional flags that modify the behavior of `getnameinfo`.
|
||||
*/
|
||||
template<typename I = IPv4>
|
||||
template<typename I = net::IPv4>
|
||||
auto getNameInfoSync(std::string ip, unsigned int port, int flags = 0) {
|
||||
typename details::IpTraits<I>::Type addr;
|
||||
details::IpTraits<I>::AddrFunc(ip.data(), port, &addr);
|
||||
@ -254,7 +251,7 @@ public:
|
||||
* @param addr A valid instance of Addr.
|
||||
* @param flags Optional flags that modify the behavior of `getnameinfo`.
|
||||
*/
|
||||
template<typename I = IPv4>
|
||||
template<typename I = net::IPv4>
|
||||
auto getNameInfoSync(Addr addr, int flags = 0) {
|
||||
getNameInfoSync<I>(addr.ip, addr.port, flags);
|
||||
}
|
||||
|
||||
@ -13,18 +13,24 @@
|
||||
namespace uvw {
|
||||
|
||||
|
||||
namespace details {
|
||||
namespace net {
|
||||
|
||||
|
||||
struct IPv4 { };
|
||||
struct IPv6 { };
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
namespace details {
|
||||
|
||||
|
||||
template<typename>
|
||||
struct IpTraits;
|
||||
|
||||
template<>
|
||||
struct IpTraits<IPv4> {
|
||||
struct IpTraits<net::IPv4> {
|
||||
using Type = sockaddr_in;
|
||||
using AddrFuncType = int(*)(const char *, int, sockaddr_in *);
|
||||
using NameFuncType = int(*)(const sockaddr_in *, char *, std::size_t);
|
||||
@ -33,7 +39,7 @@ struct IpTraits<IPv4> {
|
||||
};
|
||||
|
||||
template<>
|
||||
struct IpTraits<IPv6> {
|
||||
struct IpTraits<net::IPv6> {
|
||||
using Type = sockaddr_in6;
|
||||
using AddrFuncType = int(*)(const char *, int, sockaddr_in6 *);
|
||||
using NameFuncType = int(*)(const sockaddr_in6 *, char *, std::size_t);
|
||||
|
||||
@ -32,7 +32,7 @@ enum class UVTcpFlags: std::underlying_type_t<uv_tcp_flags> {
|
||||
*
|
||||
* TCP handles are used to represent both TCP streams and servers.<br/>
|
||||
* By default, _IPv4_ is used as a template parameter. The handle already
|
||||
* supports _IPv6_ out-of-the-box by using `uvw::TcpHandle::IPv6`.
|
||||
* supports _IPv6_ out-of-the-box by using `uvw::net::IPv6`.
|
||||
*/
|
||||
class TcpHandle final: public StreamHandle<TcpHandle, uv_tcp_t> {
|
||||
explicit TcpHandle(std::shared_ptr<Loop> ref)
|
||||
@ -46,8 +46,6 @@ class TcpHandle final: public StreamHandle<TcpHandle, uv_tcp_t> {
|
||||
public:
|
||||
using Time = std::chrono::seconds;
|
||||
using Bind = details::UVTcpFlags;
|
||||
using IPv4 = details::IPv4;
|
||||
using IPv6 = details::IPv6;
|
||||
|
||||
/**
|
||||
* @brief Creates a new tcp handle.
|
||||
@ -140,7 +138,7 @@ public:
|
||||
* @param port The port to which to bind.
|
||||
* @param flags Optional additional flags.
|
||||
*/
|
||||
template<typename I = IPv4>
|
||||
template<typename I = net::IPv4>
|
||||
void bind(std::string ip, unsigned int port, Flags<Bind> flags = Flags<Bind>{}) {
|
||||
typename details::IpTraits<I>::Type addr;
|
||||
details::IpTraits<I>::addrFunc(ip.data(), port, &addr);
|
||||
@ -163,7 +161,7 @@ public:
|
||||
* @param addr A valid instance of Addr.
|
||||
* @param flags Optional additional flags.
|
||||
*/
|
||||
template<typename I = IPv4>
|
||||
template<typename I = net::IPv4>
|
||||
void bind(Addr addr, Flags<Bind> flags = Flags<Bind>{}) {
|
||||
bind<I>(addr.ip, addr.port, flags);
|
||||
}
|
||||
@ -172,7 +170,7 @@ public:
|
||||
* @brief Gets the current address to which the handle is bound.
|
||||
* @return A valid instance of Addr, an empty one in case of errors.
|
||||
*/
|
||||
template<typename I = IPv4>
|
||||
template<typename I = net::IPv4>
|
||||
Addr sock() const noexcept {
|
||||
return details::address<I>(&uv_tcp_getsockname, get<uv_tcp_t>());
|
||||
}
|
||||
@ -181,7 +179,7 @@ public:
|
||||
* @brief Gets the address of the peer connected to the handle.
|
||||
* @return A valid instance of Addr, an empty one in case of errors.
|
||||
*/
|
||||
template<typename I = IPv4>
|
||||
template<typename I = net::IPv4>
|
||||
Addr peer() const noexcept {
|
||||
return details::address<I>(&uv_tcp_getpeername, get<uv_tcp_t>());
|
||||
}
|
||||
@ -196,7 +194,7 @@ public:
|
||||
* @param ip The address to which to bind.
|
||||
* @param port The port to which to bind.
|
||||
*/
|
||||
template<typename I = IPv4>
|
||||
template<typename I = net::IPv4>
|
||||
void connect(std::string ip, unsigned int port) {
|
||||
typename details::IpTraits<I>::Type addr;
|
||||
details::IpTraits<I>::addrFunc(ip.data(), port, &addr);
|
||||
@ -220,7 +218,7 @@ public:
|
||||
*
|
||||
* @param addr A valid instance of Addr.
|
||||
*/
|
||||
template<typename I = IPv4>
|
||||
template<typename I = net::IPv4>
|
||||
void connect(Addr addr) {
|
||||
connect<I>(addr.ip, addr.port);
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ public:
|
||||
*
|
||||
* UDP handles encapsulate UDP communication for both clients and servers.<br/>
|
||||
* By default, _IPv4_ is used as a template parameter. The handle already
|
||||
* supports _IPv6_ out-of-the-box by using `uvw::UDPHandle::IPv6`.
|
||||
* supports _IPv6_ out-of-the-box by using `uvw::net::IPv6`.
|
||||
*/
|
||||
class UDPHandle final: public Handle<UDPHandle, uv_udp_t> {
|
||||
template<typename I>
|
||||
@ -140,8 +140,6 @@ class UDPHandle final: public Handle<UDPHandle, uv_udp_t> {
|
||||
public:
|
||||
using Membership = details::UVMembership;
|
||||
using Bind = details::UVUdpFlags;
|
||||
using IPv4 = details::IPv4;
|
||||
using IPv6 = details::IPv6;
|
||||
|
||||
/**
|
||||
* @brief Creates a new udp handle.
|
||||
@ -203,7 +201,7 @@ public:
|
||||
* @param port The port to which to bind.
|
||||
* @param flags Optional additional flags.
|
||||
*/
|
||||
template<typename I = IPv4>
|
||||
template<typename I = net::IPv4>
|
||||
void bind(std::string ip, unsigned int port, Flags<Bind> flags = Flags<Bind>{}) {
|
||||
typename details::IpTraits<I>::Type addr;
|
||||
details::IpTraits<I>::addrFunc(ip.data(), port, &addr);
|
||||
@ -225,7 +223,7 @@ public:
|
||||
* @param addr A valid instance of Addr.
|
||||
* @param flags Optional additional flags.
|
||||
*/
|
||||
template<typename I = IPv4>
|
||||
template<typename I = net::IPv4>
|
||||
void bind(Addr addr, Flags<Bind> flags = Flags<Bind>{}) {
|
||||
bind<I>(addr.ip, addr.port, flags);
|
||||
}
|
||||
@ -234,7 +232,7 @@ public:
|
||||
* @brief Get the local IP and port of the UDP handle.
|
||||
* @return A valid instance of Addr, an empty one in case of errors.
|
||||
*/
|
||||
template<typename I = IPv4>
|
||||
template<typename I = net::IPv4>
|
||||
Addr sock() const noexcept {
|
||||
return details::address<I>(&uv_udp_getsockname, get<uv_udp_t>());
|
||||
}
|
||||
@ -251,7 +249,7 @@ public:
|
||||
* @param interface Interface address.
|
||||
* @param membership Action to be performed.
|
||||
*/
|
||||
template<typename I = IPv4>
|
||||
template<typename I = net::IPv4>
|
||||
void multicastMembership(std::string multicast, std::string interface, Membership membership) {
|
||||
invoke(&uv_udp_set_membership, get<uv_udp_t>(), multicast.data(), interface.data(), static_cast<uv_membership>(membership));
|
||||
}
|
||||
@ -279,7 +277,7 @@ public:
|
||||
* @brief Sets the multicast interface to send or receive data on.
|
||||
* @param interface Interface address.
|
||||
*/
|
||||
template<typename I = IPv4>
|
||||
template<typename I = net::IPv4>
|
||||
void multicastInterface(std::string interface) {
|
||||
invoke(&uv_udp_set_multicast_interface, get<uv_udp_t>(), interface.data());
|
||||
}
|
||||
@ -315,7 +313,7 @@ public:
|
||||
* @param data The data to be sent.
|
||||
* @param len The lenght of the submitted data.
|
||||
*/
|
||||
template<typename I = IPv4>
|
||||
template<typename I = net::IPv4>
|
||||
void send(std::string ip, unsigned int port, std::unique_ptr<char[]> data, ssize_t len) {
|
||||
typename details::IpTraits<I>::Type addr;
|
||||
details::IpTraits<I>::addrFunc(ip.data(), port, &addr);
|
||||
@ -344,7 +342,7 @@ public:
|
||||
* @param len The lenght of the submitted data.
|
||||
* @return Number of bytes written.
|
||||
*/
|
||||
template<typename I = IPv4>
|
||||
template<typename I = net::IPv4>
|
||||
int trySend(std::string ip, unsigned int port, std::unique_ptr<char[]> data, ssize_t len) {
|
||||
typename details::IpTraits<I>::Type addr;
|
||||
details::IpTraits<I>::addrFunc(ip.data(), port, &addr);
|
||||
@ -370,7 +368,7 @@ public:
|
||||
* An UDPDataEvent event will be emitted when the handle receives data.<br/>
|
||||
* An ErrorEvent event will be emitted in case of errors.
|
||||
*/
|
||||
template<typename I = IPv4>
|
||||
template<typename I = net::IPv4>
|
||||
void recv() {
|
||||
invoke(&uv_udp_recv_start, get<uv_udp_t>(), &allocCallback, &recvCallback<I>);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user