static int fq_client_connect_internal(fq_conn_s *conn_s) { int rv = -1; uint32_t cmd = htonl(FQ_PROTO_CMD_MODE); fq_client_disconnect_internal(conn_s); conn_s->cmd_fd = fq_socket_connect(conn_s); if(conn_s->cmd_fd < 0) goto shutdown; fq_debug(FQ_DEBUG_CONN, "connect(cmd_fd) -> %d\n", conn_s->cmd_fd); if(write(conn_s->cmd_fd, &cmd, sizeof(cmd)) != sizeof(cmd)) goto shutdown; if((rv = fq_client_do_auth(conn_s)) < 0) { fq_debug(FQ_DEBUG_CONN, "fq_client_do_auth -> %d\n", rv); goto shutdown; } if(conn_s->auth_hook) { if(conn_s->sync_hooks) enqueue_auth_hook_req(conn_s, 0); else conn_s->auth_hook((fq_client)conn_s, 0); } return 0; shutdown: if(conn_s->cmd_fd >= 0) { int toclose = conn_s->cmd_fd; conn_s->cmd_fd = -1; fq_debug(FQ_DEBUG_CONN, "close(cmd_fd) (in auth)\n"); close(toclose); if(conn_s->disconnect_hook) conn_s->disconnect_hook(conn_s); } if(conn_s->auth_hook) { if(conn_s->sync_hooks) enqueue_auth_hook_req(conn_s, rv); else conn_s->auth_hook((fq_client)conn_s, rv); } return -1; }
static int fq_client_connect_internal(fq_conn_s *conn_s) { int rv; uint32_t cmd = htonl(FQ_PROTO_CMD_MODE); fq_client_disconnect_internal(conn_s); conn_s->cmd_fd = fq_socket_connect(conn_s); if(conn_s->cmd_fd < 0) goto shutdown; if(write(conn_s->cmd_fd, &cmd, sizeof(cmd)) != sizeof(cmd)) goto shutdown; if((rv = fq_client_do_auth(conn_s)) < 0) { #ifdef DEBUG fq_debug(FQ_DEBUG_CONN, "fq_client_do_auth -> %d\n", rv); #endif goto shutdown; } return 0; shutdown: if(conn_s->cmd_fd >= 0) { close(conn_s->cmd_fd); conn_s->cmd_fd = -1; } return -1; }