Function connect

Summary

#include <src/uvw/tcp.h>

(1) void connect(const sockaddr &addr)

(2) template <typename I = IPv4>
    void connect(std::string ip, unsigned int port)

(3) template <typename I = IPv4>
    void connect(Addr addr)

#include <src/uvw/tcp.cpp>

(4) template <typename I>
    UVW_INLINE void connect(std::string ip, unsigned int port)

(5) template <typename I>
    UVW_INLINE void connect(Addr addr)

Function overload

Synopsis

#include <src/uvw/tcp.h>

void connect(const sockaddr &addr)

Description

Establishes an IPv4 or IPv6 TCP connection.

On Windows if the addr is initialized to point to an unspecified address (0.0.0.0 or ::) it will be changed to point to localhost. This is done to match the behavior of Linux systems.

A ConnectEvent event is emitted when the connection has been established.
An ErrorEvent event is emitted in case of errors during the connection.

Parameters

addr - Initialized sockaddr_in or sockaddr_in6 data structure.

Source

Lines 87-96 in src/uvw/tcp.cpp. Line 187 in src/uvw/tcp.h.

UVW_INLINE void TCPHandle::connect(const sockaddr &addr) {
    auto listener = [ptr = shared_from_this()](const auto &event, const auto &) {
        ptr->publish(event);
    };

    auto req = loop().resource<details::ConnectReq>();
    req->once<ErrorEvent>(listener);
    req->once<ConnectEvent>(listener);
    req->connect(&uv_tcp_connect, get(), &addr);
}

Synopsis

#include <src/uvw/tcp.h>

template <typename I = IPv4>
void connect(std::string ip, unsigned int port)

Description

Establishes an IPv4 or IPv6 TCP connection.

A ConnectEvent event is emitted when the connection has been established.
An ErrorEvent event is emitted in case of errors during the connection.

Parameters

ip - The address to which to bind.

port - The port to which to bind.

Source

Line 200 in src/uvw/tcp.h.

Synopsis

#include <src/uvw/tcp.h>

template <typename I = IPv4>
void connect(Addr addr)

Description

Establishes an IPv4 or IPv6 TCP connection.

A ConnectEvent event is emitted when the connection has been established.
An ErrorEvent event is emitted in case of errors during the connection.

Parameters

addr - A valid instance of Addr.

Source

Line 212 in src/uvw/tcp.h.

Synopsis

#include <src/uvw/tcp.cpp>

template <typename I>
UVW_INLINE void connect(std::string ip, unsigned int port)

Description

No description yet.

Source

Lines 73-78 in src/uvw/tcp.cpp.

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));
}

Synopsis

#include <src/uvw/tcp.cpp>

template <typename I>
UVW_INLINE void connect(Addr addr)

Description

No description yet.

Source

Lines 81-84 in src/uvw/tcp.cpp.

template<typename I>
UVW_INLINE void TCPHandle::connect(Addr addr) {
    connect<I>(std::move(addr.ip), addr.port);
}





Add Discussion as Guest

Log in