luasokcet直接调用tcp代码备份

int family = iterator->ai_family;
t_socket sock;
const char *err = inet_trycreate(&sock, family, SOCK_STREAM);
if (err) {
    continue; // check next
} else {
    t_timeout tm;
    struct addrinfo connecthints;
    memset(&connecthints, 0, sizeof(connecthints));
    connecthints.ai_socktype = SOCK_STREAM;
    /* make sure we try to connect only to the same family */
    connecthints.ai_family = family;
    
    if (family == PF_INET6) {
        int yes = 1;
        setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&yes, sizeof(yes));
    }
    timeout_markstart(&tm);
    err = inet_tryconnect(&sock, &family, (const char *)hbuf, "3006", &tm, &connecthints);
    if (err) {
        socket_destroy(&sock);
        continue; // check next
    } else {
        // find success one
        CCLOG("== xx:%s", hbuf);
    }
}

标签: none

添加新评论