static inline gint log_proto_buffered_server_read_data(LogProtoBufferedServer *self, gpointer buffer, gsize count) { gint rc; log_transport_aux_data_reinit(&self->buffer_aux); rc = self->read_data(self, buffer, count, &self->buffer_aux); return rc; }
static void test_aux_data_reinit_returns_aux_into_initial_state_without_leaks(void) { LogTransportAuxData *aux = construct_aux_with_some_data(); log_transport_aux_data_reinit(aux); assert_null(aux->peer_addr, "aux->peer_addr is not NULL after reinit"); free_aux(aux); }
/* returns: notify_code (NC_XXXX) or 0 for success */ static gint log_reader_fetch_log(LogReader *self) { gint msg_count = 0; gboolean may_read = TRUE; LogTransportAuxData aux; log_transport_aux_data_init(&aux); if (log_proto_server_handshake_in_progress(self->proto)) { return log_reader_process_handshake(self); } /* NOTE: this loop is here to decrease the load on the main loop, we try * to fetch a couple of messages in a single run (but only up to * fetch_limit). */ while (msg_count < self->options->fetch_limit && !main_loop_worker_job_quit()) { Bookmark *bookmark; const guchar *msg; gsize msg_len; LogProtoStatus status; msg = NULL; /* NOTE: may_read is used to implement multi-read checking. It * is initialized to TRUE to indicate that the protocol is * allowed to issue a read(). If multi-read is disallowed in the * protocol, it resets may_read to FALSE after the first read was issued. */ log_transport_aux_data_reinit(&aux); bookmark = ack_tracker_request_bookmark(self->super.ack_tracker); status = log_proto_server_fetch(self->proto, &msg, &msg_len, &may_read, &aux, bookmark); switch (status) { case LPS_EOF: g_sockaddr_unref(aux.peer_addr); return NC_CLOSE; case LPS_ERROR: g_sockaddr_unref(aux.peer_addr); return NC_READ_ERROR; case LPS_SUCCESS: break; default: g_assert_not_reached(); break; } if (!msg) { /* no more messages for now */ break; } if (msg_len > 0 || (self->options->flags & LR_EMPTY_LINES)) { msg_count++; ScratchBuffersMarker mark; scratch_buffers_mark(&mark); if (!log_reader_handle_line(self, msg, msg_len, &aux)) { scratch_buffers_reclaim_marked(mark); /* window is full, don't generate further messages */ break; } scratch_buffers_reclaim_marked(mark); } } log_transport_aux_data_destroy(&aux); if (msg_count == self->options->fetch_limit) self->immediate_check = TRUE; return 0; }