void fast_session_free(struct fast_session *self) { if (!self) return; fast_message_free(self->rx_messages, FAST_TEMPLATE_MAX_NUMBER); buffer_delete(self->tx_message_buffer); buffer_delete(self->tx_pmap_buffer); buffer_delete(self->rx_buffer); free(self); }
static int fast_books_join(struct fast_book_set *set, struct fast_book *book) { struct fast_message *inc_buf = NULL; struct fast_message *tmp_buf; struct fast_field *field; struct fast_message *msg; unsigned long size = 32; unsigned long pos = 0; u64 last_msg_seq_num; u64 msg_seq_num = 0; unsigned long i; if (fast_feed_open(set->snp_feeds)) goto fail; inc_buf = calloc(size, sizeof(struct fast_message)); if (!inc_buf) goto fail; book_clear_flags(book, FAST_BOOK_ACTIVE); while (!book_has_flags(book, FAST_BOOK_ACTIVE)) { if (next_increment(set, &msg)) goto fail; if (!msg) continue; if (apply_increment(set, NULL, msg)) goto fail; if (pos >= size) { size *= 2; tmp_buf = realloc(inc_buf, size * sizeof(struct fast_message)); if (!tmp_buf) goto fail; inc_buf = tmp_buf; } if (fast_message_copy(inc_buf + pos, msg)) { goto fail; } else pos++; if (!msg_seq_num) { field = fast_get_field(msg, "MsgSeqNum"); if (!field || field_state_empty(field)) goto fail; msg_seq_num = field->uint_value; } if (next_snapshot(set, &msg)) goto fail; if (!msg) continue; field = fast_get_field(msg, "LastMsgSeqNumProcessed"); if (!field || field_state_empty(field)) goto fail; last_msg_seq_num = field->uint_value; if (last_msg_seq_num < msg_seq_num) continue; if (apply_snapshot(set, book, msg)) goto fail; } if (!pos) goto fail; for (i = 0; i < pos; i++) { msg = inc_buf + i; field = fast_get_field(msg, "MsgSeqNum"); if (!field || field_state_empty(field)) goto fail; msg_seq_num = field->uint_value; if (msg_seq_num <= last_msg_seq_num) continue; if (apply_increment(set, book, msg)) goto fail; } if (fast_feed_close(set->snp_feeds)) goto fail; fast_message_free(inc_buf, pos); return 0; fail: fast_feed_close(set->snp_feeds); fast_message_free(inc_buf, pos); return -1; }