From dfd347b5f7befae5dc6ceb07d67e8379892aa6a7 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Mon, 22 Aug 2016 14:34:49 +0200 Subject: [PATCH] minor changes --- README.md | 4 ++-- src/uvw/dns.hpp | 11 ++++------- src/uvw/misc.hpp | 12 +++++++++--- src/uvw/tcp.hpp | 16 +++++++--------- src/uvw/udp.hpp | 20 +++++++++----------- 5 files changed, 31 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 774b3c14..6c759d5e 100644 --- a/README.md +++ b/README.md @@ -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("127.0.0.1", 4242)`.
-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("127.0.0.1", 4242)`.
+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. diff --git a/src/uvw/dns.hpp b/src/uvw/dns.hpp index 2fca4ee0..1b0ef12a 100644 --- a/src/uvw/dns.hpp +++ b/src/uvw/dns.hpp @@ -198,9 +198,6 @@ class GetNameInfoReq final: public Request { 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 + template void getNameInfo(std::string ip, unsigned int port, int flags = 0) { typename details::IpTraits::Type addr; details::IpTraits::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 + template void getNameInfo(Addr addr, int flags = 0) { getNameInfo(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 + template auto getNameInfoSync(std::string ip, unsigned int port, int flags = 0) { typename details::IpTraits::Type addr; details::IpTraits::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 + template auto getNameInfoSync(Addr addr, int flags = 0) { getNameInfoSync(addr.ip, addr.port, flags); } diff --git a/src/uvw/misc.hpp b/src/uvw/misc.hpp index 544396e5..03c01d7d 100644 --- a/src/uvw/misc.hpp +++ b/src/uvw/misc.hpp @@ -13,18 +13,24 @@ namespace uvw { -namespace details { +namespace net { struct IPv4 { }; struct IPv6 { }; +} + + +namespace details { + + template struct IpTraits; template<> -struct IpTraits { +struct IpTraits { 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 { }; template<> -struct IpTraits { +struct IpTraits { using Type = sockaddr_in6; using AddrFuncType = int(*)(const char *, int, sockaddr_in6 *); using NameFuncType = int(*)(const sockaddr_in6 *, char *, std::size_t); diff --git a/src/uvw/tcp.hpp b/src/uvw/tcp.hpp index 179254ae..7fecb042 100644 --- a/src/uvw/tcp.hpp +++ b/src/uvw/tcp.hpp @@ -32,7 +32,7 @@ enum class UVTcpFlags: std::underlying_type_t { * * TCP handles are used to represent both TCP streams and servers.
* 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 { explicit TcpHandle(std::shared_ptr ref) @@ -46,8 +46,6 @@ class TcpHandle final: public StreamHandle { 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 + template void bind(std::string ip, unsigned int port, Flags flags = Flags{}) { typename details::IpTraits::Type addr; details::IpTraits::addrFunc(ip.data(), port, &addr); @@ -163,7 +161,7 @@ public: * @param addr A valid instance of Addr. * @param flags Optional additional flags. */ - template + template void bind(Addr addr, Flags flags = Flags{}) { bind(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 + template Addr sock() const noexcept { return details::address(&uv_tcp_getsockname, get()); } @@ -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 + template Addr peer() const noexcept { return details::address(&uv_tcp_getpeername, get()); } @@ -196,7 +194,7 @@ public: * @param ip The address to which to bind. * @param port The port to which to bind. */ - template + template void connect(std::string ip, unsigned int port) { typename details::IpTraits::Type addr; details::IpTraits::addrFunc(ip.data(), port, &addr); @@ -220,7 +218,7 @@ public: * * @param addr A valid instance of Addr. */ - template + template void connect(Addr addr) { connect(addr.ip, addr.port); } diff --git a/src/uvw/udp.hpp b/src/uvw/udp.hpp index f4a581b3..cdc45c5b 100644 --- a/src/uvw/udp.hpp +++ b/src/uvw/udp.hpp @@ -103,7 +103,7 @@ public: * * UDP handles encapsulate UDP communication for both clients and servers.
* 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 { template @@ -140,8 +140,6 @@ class UDPHandle final: public Handle { 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 + template void bind(std::string ip, unsigned int port, Flags flags = Flags{}) { typename details::IpTraits::Type addr; details::IpTraits::addrFunc(ip.data(), port, &addr); @@ -225,7 +223,7 @@ public: * @param addr A valid instance of Addr. * @param flags Optional additional flags. */ - template + template void bind(Addr addr, Flags flags = Flags{}) { bind(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 + template Addr sock() const noexcept { return details::address(&uv_udp_getsockname, get()); } @@ -251,7 +249,7 @@ public: * @param interface Interface address. * @param membership Action to be performed. */ - template + template void multicastMembership(std::string multicast, std::string interface, Membership membership) { invoke(&uv_udp_set_membership, get(), multicast.data(), interface.data(), static_cast(membership)); } @@ -279,7 +277,7 @@ public: * @brief Sets the multicast interface to send or receive data on. * @param interface Interface address. */ - template + template void multicastInterface(std::string interface) { invoke(&uv_udp_set_multicast_interface, get(), interface.data()); } @@ -315,7 +313,7 @@ public: * @param data The data to be sent. * @param len The lenght of the submitted data. */ - template + template void send(std::string ip, unsigned int port, std::unique_ptr data, ssize_t len) { typename details::IpTraits::Type addr; details::IpTraits::addrFunc(ip.data(), port, &addr); @@ -344,7 +342,7 @@ public: * @param len The lenght of the submitted data. * @return Number of bytes written. */ - template + template int trySend(std::string ip, unsigned int port, std::unique_ptr data, ssize_t len) { typename details::IpTraits::Type addr; details::IpTraits::addrFunc(ip.data(), port, &addr); @@ -370,7 +368,7 @@ public: * An UDPDataEvent event will be emitted when the handle receives data.
* An ErrorEvent event will be emitted in case of errors. */ - template + template void recv() { invoke(&uv_udp_recv_start, get(), &allocCallback, &recvCallback); }