Exemple #1
0
void TCPSocket::connect(const net::Address& peerAddress) 
{
    TraceLS(this) << "Connecting to " << peerAddress << endl;
    init();
    auto req = new uv_connect_t;
    req->data = this;
    int r = uv_tcp_connect(req, ptr<uv_tcp_t>(), peerAddress.addr(), internal::onConnect);
    if (r) setAndThrowError("TCP connect failed", r);
}
Exemple #2
0
void TCPSocket::bind(const net::Address& address, unsigned flags) 
{
    TraceLS(this) << "Binding on " << address << endl;
    init();
    int r;
    switch (address.af()) {
    case AF_INET:
        r = uv_tcp_bind(ptr<uv_tcp_t>(), address.addr(), flags);
        break;
    //case AF_INET6:
    //    r = uv_tcp_bind6(ptr<uv_tcp_t>(), *reinterpret_cast<const sockaddr_in6*>(address.addr()));
    //    break;
    default:
        throw std::runtime_error("Unexpected address family");
    }
    if (r) setAndThrowError("TCP bind failed", r);
}