diff --git a/src/uvw/tcp.cpp b/src/uvw/tcp.cpp index cb3a2147..8c235f41 100644 --- a/src/uvw/tcp.cpp +++ b/src/uvw/tcp.cpp @@ -40,6 +40,47 @@ UVW_INLINE void TCPHandle::bind(const sockaddr &addr, Flags opts) { } +template +UVW_INLINE void TCPHandle::bind(std::string ip, unsigned int port, Flags opts) +{ + typename details::IpTraits::Type addr; + details::IpTraits::addrFunc(ip.data(), port, &addr); + bind(reinterpret_cast(addr), std::move(opts)); +} + + +template +UVW_INLINE void TCPHandle::bind(Addr addr, Flags opts) { + bind(std::move(addr.ip), addr.port, std::move(opts)); +} + + +template +UVW_INLINE Addr TCPHandle::sock() const noexcept { + return details::address(&uv_tcp_getsockname, get()); +} + + +template +UVW_INLINE Addr TCPHandle::peer() const noexcept { + return details::address(&uv_tcp_getpeername, get()); +} + + +template +UVW_INLINE void TCPHandle::connect(std::string ip, unsigned int port) { + typename details::IpTraits::Type addr; + details::IpTraits::addrFunc(ip.data(), port, &addr); + connect(reinterpret_cast(addr)); +} + + +template +UVW_INLINE void TCPHandle::connect(Addr addr) { + connect(std::move(addr.ip), addr.port); +} + + UVW_INLINE void TCPHandle::connect(const sockaddr &addr) { auto listener = [ptr = shared_from_this()](const auto &event, const auto &) { ptr->publish(event); diff --git a/src/uvw/tcp.h b/src/uvw/tcp.h index 4b5e74f8..83e10edb 100644 --- a/src/uvw/tcp.h +++ b/src/uvw/tcp.h @@ -135,11 +135,7 @@ public: * @param opts Optional additional flags. */ template - void bind(std::string ip, unsigned int port, Flags opts = Flags{}) { - typename details::IpTraits::Type addr; - details::IpTraits::addrFunc(ip.data(), port, &addr); - bind(reinterpret_cast(addr), std::move(opts)); - } + void bind(std::string ip, unsigned int port, Flags opts = Flags{}); /** * @brief Binds the handle to an address and port. @@ -158,27 +154,21 @@ public: * @param opts Optional additional flags. */ template - void bind(Addr addr, Flags opts = Flags{}) { - bind(std::move(addr.ip), addr.port, std::move(opts)); - } + void bind(Addr addr, Flags opts = Flags{}); /** * @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 - Addr sock() const noexcept { - return details::address(&uv_tcp_getsockname, get()); - } + Addr sock() const noexcept; /** * @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 - Addr peer() const noexcept { - return details::address(&uv_tcp_getpeername, get()); - } + Addr peer() const noexcept; /** * @brief Establishes an IPv4 or IPv6 TCP connection. @@ -206,11 +196,7 @@ public: * @param port The port to which to bind. */ template - void connect(std::string ip, unsigned int port) { - typename details::IpTraits::Type addr; - details::IpTraits::addrFunc(ip.data(), port, &addr); - connect(reinterpret_cast(addr)); - } + void connect(std::string ip, unsigned int port); /** * @brief Establishes an IPv4 or IPv6 TCP connection. @@ -222,9 +208,7 @@ public: * @param addr A valid instance of Addr. */ template - void connect(Addr addr) { - connect(std::move(addr.ip), addr.port); - } + void connect(Addr addr); /** * @brief Resets a TCP connection by sending a RST packet.