static int stomp_check_for_frame(stomp_connection *connection) { struct pollfd pfd; pfd.fd = connection->socket; pfd.events = POLLIN | POLLPRI; poll(&pfd, 1, 0); if (pfd.revents & ( POLLIN | POLLPRI)) { stomp_frame frame; if (!stomp_receive_frame(connection, &frame)) return FALSE; if (!strcmp(frame.command, "ERROR")) { msg_error("ERROR frame received from stomp_server", NULL); stomp_frame_deinit(&frame); return FALSE; } /* According to stomp protocol, here only ERROR or RECEIPT frames can come, so we missed a RECEIPT frame here, our bad. */ stomp_frame_deinit(&frame); return TRUE; } return TRUE; }
static gboolean afstomp_dd_connect(STOMPDestDriver *self, gboolean reconnect) { stomp_frame frame; if (reconnect && self->conn) return TRUE; if (!afstomp_try_connect(self)) return FALSE; afstomp_create_connect_frame(self, &frame); if (!afstomp_send_frame(self, &frame)) { msg_error("Sending CONNECT frame to STOMP server failed!", NULL); return FALSE; } stomp_receive_frame(self->conn, &frame); if (strcmp(frame.command, "CONNECTED")) { msg_debug("Error connecting to STOMP server, stomp server did not accept CONNECT request", NULL); stomp_frame_deinit(&frame); return FALSE; } msg_debug("Connecting to STOMP succeeded", evt_tag_str("driver", self->super.super.super.id), NULL); stomp_frame_deinit(&frame); return TRUE; }
static gboolean afstomp_worker_publish(STOMPDestDriver *self, LogMessage *msg) { gboolean success = TRUE; SBGString *body = NULL; stomp_frame frame; stomp_frame recv_frame; gchar seq_num[16]; if (!self->conn) { msg_error("STOMP server is not connected, not sending message!", NULL); return FALSE; } body = sb_gstring_acquire(); stomp_frame_init(&frame, "SEND", sizeof("SEND")); if (self->persistent) stomp_frame_add_header(&frame, "persistent", "true"); stomp_frame_add_header(&frame, "destination", self->destination); if (self->ack_needed) { g_snprintf(seq_num, sizeof(seq_num), "%i", self->super.seq_num); stomp_frame_add_header(&frame, "receipt", seq_num); }; value_pairs_foreach(self->vp, afstomp_vp_foreach, msg, self->super.seq_num, LTZ_SEND, &self->template_options, &frame); afstomp_set_frame_body(self, body, &frame, msg); if (!afstomp_send_frame(self, &frame)) { msg_error("Error while inserting into STOMP server", NULL); success = FALSE; } if (success && self->ack_needed) success = stomp_receive_frame(self->conn, &recv_frame); sb_gstring_release(body); return success; }