int tcp_check_thread(thread_t * thread) { checker_t *checker; tcp_checker_t *tcp_check; int status; checker = THREAD_ARG(thread); tcp_check = CHECKER_ARG(checker); status = tcp_socket_state(thread->u.fd, thread, tcp_check_thread); /* If status = connect_success, TCP connection to remote host is established. * Otherwise we have a real connection error or connection timeout. */ if (status == connect_success) { close(thread->u.fd); if (!svr_checker_up(UP, checker->id, checker->rs)) { log_message(LOG_INFO, "TCP connection to [%s]:%d success." , inet_sockaddrtos(&tcp_check->dst) , ntohs(inet_sockaddrport(&tcp_check->dst))); smtp_alert(checker->rs, NULL, NULL, "UP", "=> TCP CHECK succeed on service <="); update_svr_checker_state(UP, checker->id , checker->vs , checker->rs); } } else { if (svr_checker_up(DOWN, checker->id, checker->rs)) { log_message(LOG_INFO, "TCP connection to [%s]:%d failed !!!" , inet_sockaddrtos(&tcp_check->dst) , ntohs(inet_sockaddrport(&tcp_check->dst))); smtp_alert(checker->rs, NULL, NULL, "DOWN", "=> TCP CHECK failed on service <="); update_svr_checker_state(DOWN, checker->id , checker->vs , checker->rs); } } /* Register next timer checker */ if (status != connect_in_progress) thread_add_timer(thread->master, tcp_connect_thread, checker, checker->vs->delay_loop); return 0; }
int tcp_check_thread(thread_t * thread) { SOCK *sock_obj = THREAD_ARG(thread); int ret = 1; sock_obj->status = tcp_socket_state(thread->u.fd, thread, req->addr_ip, req->addr_port, tcp_check_thread); switch (sock_obj->status) { case connect_error: DBG("Error connecting server [%s:%d].\n", inet_ntop2(req->addr_ip), ntohs(req->addr_port)); thread_add_terminate_event(thread->master); return -1; break; case connect_timeout: DBG("Timeout connecting server [%s:%d].\n", inet_ntop2(req->addr_ip), ntohs(req->addr_port)); thread_add_terminate_event(thread->master); return -1; break; case connect_success:{ if (req->ssl) ret = ssl_connect(thread); if (ret) { /* Remote WEB server is connected. * Unlock eventual locked socket. */ sock_obj->lock = 0; thread_add_event(thread->master, http_request_thread, sock_obj, 0); } else { DBG("Connection trouble to: [%s:%d].\n", inet_ntop2(req->addr_ip), ntohs(req->addr_port)); if (req->ssl) ssl_printerr(SSL_get_error (sock_obj->ssl, ret)); sock_obj->status = connect_error; return -1; } } break; } return 1; }
static int connection_in_progress(thread_t * thread) { int status; DBG("SMTP connection to %s now IN_PROGRESS.", FMT_SMTP_HOST()); /* * Here we use the propriety of a union structure, * each element of the structure have the same value. */ status = tcp_socket_state(thread->u.fd, thread, connection_in_progress); if (status != connect_in_progress) SMTP_FSM_SEND(status, thread); return 0; }
static int connection_in_progress(thread_t * thread) { int status; DBG("SMTP connection to [%s]:%d now IN_PROGRESS.", inet_sockaddrtos(&global_data->smtp_server), SMTP_PORT); /* * Here we use the propriety of a union structure, * each element of the structure have the same value. */ status = tcp_socket_state(thread->u.fd, thread, connection_in_progress); if (status != connect_in_progress) SMTP_FSM_SEND(status, thread); return 0; }