static inline int amqp_check_status(rmq_params_t *rmqp, int r) { if (r != 0) { LM_ERR("Unknown error while sending\n"); /* we close the connection here to be able to re-connect later */ rmq_destroy_param(rmqp); return -1; } return 0; }
void rmq_destroy(evi_reply_sock *sock) { if (!sock) return; if ((sock->flags & EVI_ADDRESS) && sock->address.s) shm_free(sock->address.s); if ((sock->flags & EVI_PARAMS) && sock->params) { rmq_free_param((rmq_params_t *)sock->params); rmq_destroy_param((rmq_params_t *)sock->params); } shm_free(sock); }
static int rmq_reconnect(evi_reply_sock *sock) { rmq_params_t * rmqp = (rmq_params_t *)sock->params; if (!rmqp || !(rmqp->flags & RMQ_PARAM_EXCH)) { LM_ERR("not enough socket info\n"); return -1; } // rmq_print(sock); if (!(rmqp->flags & RMQ_PARAM_CONN) || !rmqp->conn) { /* init new connection */ if (!(rmqp->conn = amqp_new_connection())) { LM_ERR("cannot create new connection\n"); return -1; } rmqp->flags |= RMQ_PARAM_CONN; rmqp->sock = amqp_open_socket(sock->address.s, sock->port); if (rmqp->sock < 0) { LM_ERR("cannot opens socket\n"); goto destroy_rmqp; } amqp_set_sockfd(rmqp->conn, rmqp->sock); if (rmq_error("Logging in", amqp_login(rmqp->conn, RMQ_DEFAULT_VHOST, 0, RMQ_DEFAULT_MAX, 0, AMQP_SASL_METHOD_PLAIN, rmqp->flags & RMQ_PARAM_USER ? rmqp->user.s : RMQ_DEFAULT_UP, rmqp->flags & RMQ_PARAM_PASS ? rmqp->pass.s : RMQ_DEFAULT_UP))) goto destroy_rmqp; } if (!(rmqp->flags & RMQ_PARAM_CHAN)) { rmqp->channel = 1; amqp_channel_open(rmqp->conn, rmqp->channel); rmqp->flags |= RMQ_PARAM_CHAN; if (rmq_error("Opening channel", amqp_get_rpc_reply(rmqp->conn))) goto destroy_rmqp; } return 0; destroy_rmqp: rmq_destroy_param(rmqp); return -1; }
static inline int amqp_check_status(rmq_params_t *rmqp, int r) { switch (r) { case AMQP_STATUS_OK: return 0; case AMQP_STATUS_NO_MEMORY: LM_ERR("no more memory\n"); goto no_close; case AMQP_STATUS_TABLE_TOO_BIG: LM_ERR("A table in the properties was too large to fit in a single frame\n"); goto no_close; case AMQP_STATUS_HEARTBEAT_TIMEOUT: LM_ERR("heartbeat timeout\n"); break; case AMQP_STATUS_CONNECTION_CLOSED: LM_ERR("Connection closed\n"); break; /* this should not happend since we do not use ssl */ case AMQP_STATUS_SSL_ERROR: LM_ERR("SSL error\n"); break; case AMQP_STATUS_TCP_ERROR: LM_ERR("TCP error: %s(%d)\n", strerror(errno), errno); break; default: LM_ERR("Unknown error: %s(%d)\n", strerror(errno), errno); break; } /* we close the connection here to be able to re-connect later */ rmq_destroy_param(rmqp); no_close: return r; }
static int rmq_reconnect(evi_reply_sock *sock) { rmq_params_t * rmqp = (rmq_params_t *)sock->params; #if defined AMQP_VERSION_v04 amqp_socket_t *amqp_sock; #endif int socket; if (!rmqp || !(rmqp->flags & RMQ_PARAM_RKEY)) { LM_ERR("not enough socket info\n"); return -1; } if (!(rmqp->flags & RMQ_PARAM_CONN) || !rmqp->conn) { /* init new connection */ if (!(rmqp->conn = amqp_new_connection())) { LM_ERR("cannot create new connection\n"); return -1; } rmqp->flags |= RMQ_PARAM_CONN; #if defined AMQP_VERSION_v04 amqp_sock = amqp_tcp_socket_new(rmqp->conn); if (!amqp_sock) { LM_ERR("cannot create AMQP socket\n"); goto destroy_rmqp; } socket = amqp_socket_open(amqp_sock, sock->address.s, sock->port); if (socket < 0) { LM_ERR("cannot open AMQP socket\n"); goto destroy_rmqp; } #else socket = amqp_open_socket(sock->address.s, sock->port); if (socket < 0) { LM_ERR("cannot open AMQP socket\n"); goto destroy_rmqp; } amqp_set_sockfd(rmqp->conn, socket); #endif if (rmq_error("Logging in", amqp_login( rmqp->conn, RMQ_DEFAULT_VHOST, 0, RMQ_DEFAULT_MAX, rmqp->heartbeat, AMQP_SASL_METHOD_PLAIN, rmqp->flags & RMQ_PARAM_USER ? rmqp->user.s : RMQ_DEFAULT_UP, rmqp->flags & RMQ_PARAM_PASS ? rmqp->pass.s : RMQ_DEFAULT_UP))) goto destroy_rmqp; } if (!(rmqp->flags & RMQ_PARAM_CHAN)) { rmqp->channel = 1; amqp_channel_open(rmqp->conn, rmqp->channel); rmqp->flags |= RMQ_PARAM_CHAN; if (rmq_error("Opening channel", amqp_get_rpc_reply(rmqp->conn))) goto destroy_rmqp; } return 0; destroy_rmqp: rmq_destroy_param(rmqp); return -1; }