int tcp_connect_thread(thread_t * thread) { SOCK *sock_obj = THREAD_ARG(thread); if(req->dst){ if(req->dst->ai_family == AF_INET6) { if ((sock_obj->fd = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP)) == -1) { DBG("WEB connection fail to create socket.\n"); return 0; } } else { if ((sock_obj->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) { DBG("WEB connection fail to create socket.\n"); return 0; } } } else { if ((sock_obj->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) { DBG("WEB connection fail to create socket.\n"); return 0; } } sock->status = tcp_connect(sock_obj->fd, req); /* handle tcp connection status & register check worker thread */ tcp_connection_state(sock_obj->fd, sock_obj->status, thread, tcp_check_thread, HTTP_CNX_TIMEOUT); return 0; }
int tcp_connect_thread(thread_t * thread) { checker_t *checker = THREAD_ARG(thread); tcp_checker_t *tcp_check = CHECKER_ARG(checker); int fd; int status; /* * Register a new checker thread & return * if checker is disabled */ if (!CHECKER_ENABLED(checker)) { thread_add_timer(thread->master, tcp_connect_thread, checker, checker->vs->delay_loop); return 0; } if ((fd = socket(tcp_check->dst.ss_family, SOCK_STREAM, IPPROTO_TCP)) == -1) { DBG("TCP connect fail to create socket."); return 0; } status = tcp_bind_connect(fd, &tcp_check->dst, &tcp_check->bindto); if (status == connect_error) { thread_add_timer(thread->master, tcp_connect_thread, checker, checker->vs->delay_loop); } /* handle tcp connection status & register check worker thread */ tcp_connection_state(fd, status, thread, tcp_check_thread, tcp_check->connection_to); return 0; }
int tcp_connect_thread(thread_t * thread) { SOCK *sock_obj = THREAD_ARG(thread); if ((sock_obj->fd = socket((req->dst && req->dst->ai_family == AF_INET6) ? AF_INET6 : AF_INET, SOCK_STREAM #ifdef SOCK_CLOEXEC | SOCK_CLOEXEC #endif , IPPROTO_TCP)) == -1) { DBG("WEB connection fail to create socket.\n"); return 0; } #ifndef SOCK_CLOEXEC fcntl(sock_obj->fd, F_SETFD, fcntl(sock_obj->fd, F_GETFD) | FD_CLOEXEC); #endif sock->status = tcp_connect(sock_obj->fd, req); /* handle tcp connection status & register check worker thread */ tcp_connection_state(sock_obj->fd, sock_obj->status, thread, tcp_check_thread, HTTP_CNX_TIMEOUT); return 0; }