improve tcp instantiations
Signed-off-by: Stefano Fiorentino <stefano.fiore84@gmail.com>
This commit is contained in:
parent
d611ca264f
commit
8872af2d86
@ -40,6 +40,47 @@ UVW_INLINE void TCPHandle::bind(const sockaddr &addr, Flags<Bind> opts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename I>
|
||||||
|
UVW_INLINE void TCPHandle::bind(std::string ip, unsigned int port, Flags<Bind> opts)
|
||||||
|
{
|
||||||
|
typename details::IpTraits<I>::Type addr;
|
||||||
|
details::IpTraits<I>::addrFunc(ip.data(), port, &addr);
|
||||||
|
bind(reinterpret_cast<const sockaddr &>(addr), std::move(opts));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename I>
|
||||||
|
UVW_INLINE void TCPHandle::bind(Addr addr, Flags<Bind> opts) {
|
||||||
|
bind<I>(std::move(addr.ip), addr.port, std::move(opts));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename I>
|
||||||
|
UVW_INLINE Addr TCPHandle::sock() const noexcept {
|
||||||
|
return details::address<I>(&uv_tcp_getsockname, get());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename I>
|
||||||
|
UVW_INLINE Addr TCPHandle::peer() const noexcept {
|
||||||
|
return details::address<I>(&uv_tcp_getpeername, get());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename I>
|
||||||
|
UVW_INLINE void TCPHandle::connect(std::string ip, unsigned int port) {
|
||||||
|
typename details::IpTraits<I>::Type addr;
|
||||||
|
details::IpTraits<I>::addrFunc(ip.data(), port, &addr);
|
||||||
|
connect(reinterpret_cast<const sockaddr &>(addr));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename I>
|
||||||
|
UVW_INLINE void TCPHandle::connect(Addr addr) {
|
||||||
|
connect<I>(std::move(addr.ip), addr.port);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
UVW_INLINE void TCPHandle::connect(const sockaddr &addr) {
|
UVW_INLINE void TCPHandle::connect(const sockaddr &addr) {
|
||||||
auto listener = [ptr = shared_from_this()](const auto &event, const auto &) {
|
auto listener = [ptr = shared_from_this()](const auto &event, const auto &) {
|
||||||
ptr->publish(event);
|
ptr->publish(event);
|
||||||
|
|||||||
@ -135,11 +135,7 @@ public:
|
|||||||
* @param opts Optional additional flags.
|
* @param opts Optional additional flags.
|
||||||
*/
|
*/
|
||||||
template<typename I = IPv4>
|
template<typename I = IPv4>
|
||||||
void bind(std::string ip, unsigned int port, Flags<Bind> opts = Flags<Bind>{}) {
|
void bind(std::string ip, unsigned int port, Flags<Bind> opts = Flags<Bind>{});
|
||||||
typename details::IpTraits<I>::Type addr;
|
|
||||||
details::IpTraits<I>::addrFunc(ip.data(), port, &addr);
|
|
||||||
bind(reinterpret_cast<const sockaddr &>(addr), std::move(opts));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Binds the handle to an address and port.
|
* @brief Binds the handle to an address and port.
|
||||||
@ -158,27 +154,21 @@ public:
|
|||||||
* @param opts Optional additional flags.
|
* @param opts Optional additional flags.
|
||||||
*/
|
*/
|
||||||
template<typename I = IPv4>
|
template<typename I = IPv4>
|
||||||
void bind(Addr addr, Flags<Bind> opts = Flags<Bind>{}) {
|
void bind(Addr addr, Flags<Bind> opts = Flags<Bind>{});
|
||||||
bind<I>(std::move(addr.ip), addr.port, std::move(opts));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gets the current address to which the handle is bound.
|
* @brief Gets the current address to which the handle is bound.
|
||||||
* @return A valid instance of Addr, an empty one in case of errors.
|
* @return A valid instance of Addr, an empty one in case of errors.
|
||||||
*/
|
*/
|
||||||
template<typename I = IPv4>
|
template<typename I = IPv4>
|
||||||
Addr sock() const noexcept {
|
Addr sock() const noexcept;
|
||||||
return details::address<I>(&uv_tcp_getsockname, get());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gets the address of the peer connected to the handle.
|
* @brief Gets the address of the peer connected to the handle.
|
||||||
* @return A valid instance of Addr, an empty one in case of errors.
|
* @return A valid instance of Addr, an empty one in case of errors.
|
||||||
*/
|
*/
|
||||||
template<typename I = IPv4>
|
template<typename I = IPv4>
|
||||||
Addr peer() const noexcept {
|
Addr peer() const noexcept;
|
||||||
return details::address<I>(&uv_tcp_getpeername, get());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Establishes an IPv4 or IPv6 TCP connection.
|
* @brief Establishes an IPv4 or IPv6 TCP connection.
|
||||||
@ -206,11 +196,7 @@ public:
|
|||||||
* @param port The port to which to bind.
|
* @param port The port to which to bind.
|
||||||
*/
|
*/
|
||||||
template<typename I = IPv4>
|
template<typename I = IPv4>
|
||||||
void connect(std::string ip, unsigned int port) {
|
void connect(std::string ip, unsigned int port);
|
||||||
typename details::IpTraits<I>::Type addr;
|
|
||||||
details::IpTraits<I>::addrFunc(ip.data(), port, &addr);
|
|
||||||
connect(reinterpret_cast<const sockaddr &>(addr));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Establishes an IPv4 or IPv6 TCP connection.
|
* @brief Establishes an IPv4 or IPv6 TCP connection.
|
||||||
@ -222,9 +208,7 @@ public:
|
|||||||
* @param addr A valid instance of Addr.
|
* @param addr A valid instance of Addr.
|
||||||
*/
|
*/
|
||||||
template<typename I = IPv4>
|
template<typename I = IPv4>
|
||||||
void connect(Addr addr) {
|
void connect(Addr addr);
|
||||||
connect<I>(std::move(addr.ip), addr.port);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Resets a TCP connection by sending a RST packet.
|
* @brief Resets a TCP connection by sending a RST packet.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user