#include <inttypes.h>
#include <fcntl.h>
#include <sys/mman.h>
+#include <poll.h>
#include <babeltrace/ctf/ctf-index.h>
#include "lttng-live.h"
#include "lttng-viewer-abi.h"
+#define ACTIVE_POLL_DELAY 100 /* ms */
+
/*
* Memory allocation zeroed
*/
ret = ctf_append_trace_metadata(
viewer_stream->ctf_trace->handle->td,
metadata->ctf_trace->metadata_fp);
- if (ret != 0) {
+ /* We accept empty metadata packets */
+ if (ret != 0 && ret != -ENOENT) {
fprintf(stderr, "[error] Appending metadata\n");
goto error;
}
+ ret = 0;
error:
return ret;
ret = append_metadata(ctx, stream);
if (ret)
goto error;
- goto retry;
}
if (rp.flags & LTTNG_VIEWER_FLAG_NEW_STREAM) {
+ printf_verbose("get_data_packet: new streams needed\n");
ret = ask_new_streams(ctx);
if (ret < 0)
goto error;
- g_hash_table_foreach(ctx->session->ctf_traces, add_traces,
- ctx->bt_ctx);
+ g_hash_table_foreach(ctx->session->ctf_traces,
+ add_traces, ctx->bt_ctx);
+ }
+ if (rp.flags & (LTTNG_VIEWER_FLAG_NEW_METADATA
+ | LTTNG_VIEWER_FLAG_NEW_STREAM)) {
+ goto retry;
}
fprintf(stderr, "[error] get_data_packet: error\n");
ret = -1;
goto error;
}
assert(ret_len == len);
-
+ ret = 0;
end:
error:
return ret;
if (ret > 0) {
len_read += ret;
}
+ if (!len_read) {
+ (void) poll(NULL, 0, ACTIVE_POLL_DELAY);
+ }
} while (ret > 0 || !len_read);
if (fclose(metadata_stream->metadata_fp_write))
ret = ask_new_streams(ctx);
if (ret < 0)
goto error;
- g_hash_table_foreach(ctx->session->ctf_traces, add_traces,
- ctx->bt_ctx);
+ g_hash_table_foreach(ctx->session->ctf_traces,
+ add_traces, ctx->bt_ctx);
}
break;
case LTTNG_VIEWER_INDEX_RETRY:
printf_verbose("get_next_index: retry\n");
- sleep(1);
+ (void) poll(NULL, 0, ACTIVE_POLL_DELAY);
goto retry;
case LTTNG_VIEWER_INDEX_HUP:
printf_verbose("get_next_index: stream hung up\n");
sout = container_of(td_write, struct ctf_text_stream_pos,
trace_descriptor);
- if (!sout->parent.event_cb)
+ if (!sout->parent.event_cb) {
goto end_free;
+ }
ret = lttng_live_create_viewer_session(ctx);
if (ret < 0) {
int flags;
while (!ctx->session->stream_count) {
- if (ctx->session_ids->len == 0)
+ if (ctx->session_ids->len == 0) {
goto end_free;
+ }
ret = ask_new_streams(ctx);
- if (ret < 0)
+ if (ret < 0) {
goto end_free;
+ }
+ if (!ctx->session->stream_count) {
+ (void) poll(NULL, 0, ACTIVE_POLL_DELAY);
+ }
}
g_hash_table_foreach(ctx->session->ctf_traces, add_traces,