struct lttng_live_viewer_stream *viewer_stream,
char **metadata_buf);
+static
+ssize_t lttng_live_recv(int fd, void *buf, size_t len)
+{
+ ssize_t ret;
+ size_t copied = 0, to_copy = len;
+
+ do {
+ ret = recv(fd, buf + copied, to_copy, 0);
+ if (ret > 0) {
+ assert(ret <= to_copy);
+ copied += ret;
+ to_copy -= ret;
+ }
+ } while ((ret > 0 && to_copy > 0)
+ || (ret < 0 && errno == EINTR));
+ if (ret > 0)
+ ret = copied;
+ /* ret = 0 means orderly shutdown, ret < 0 is error. */
+ return ret;
+}
+
+static
+ssize_t lttng_live_send(int fd, const void *buf, size_t len)
+{
+ ssize_t ret;
+
+ do {
+ ret = send(fd, buf, len, MSG_NOSIGNAL);
+ } while (ret < 0 && errno == EINTR);
+ return ret;
+}
+
int lttng_live_connect_viewer(struct lttng_live_ctx *ctx)
{
struct hostent *host;
connect.minor = htobe32(LTTNG_LIVE_MINOR);
connect.type = htobe32(LTTNG_VIEWER_CLIENT_COMMAND);
- do {
- ret_len = send(ctx->control_sock, &cmd, sizeof(cmd), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_send(ctx->control_sock, &cmd, sizeof(cmd));
if (ret_len < 0) {
perror("[error] Error sending cmd");
ret = ret_len;
}
assert(ret_len == sizeof(cmd));
- do {
- ret_len = send(ctx->control_sock, &connect, sizeof(connect), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_send(ctx->control_sock, &connect, sizeof(connect));
if (ret_len < 0) {
perror("[error] Error sending version");
ret = ret_len;
}
assert(ret_len == sizeof(connect));
- do {
- ret_len = recv(ctx->control_sock, &connect, sizeof(connect), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_recv(ctx->control_sock, &connect, sizeof(connect));
if (ret_len == 0) {
fprintf(stderr, "[error] Remote side has closed connection\n");
ret = -1;
cmd.data_size = 0;
cmd.cmd_version = 0;
- do {
- ret_len = send(ctx->control_sock, &cmd, sizeof(cmd), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_send(ctx->control_sock, &cmd, sizeof(cmd));
if (ret_len < 0) {
perror("[error] Error sending cmd");
ret = ret_len;
}
assert(ret_len == sizeof(cmd));
- do {
- ret_len = recv(ctx->control_sock, &list, sizeof(list), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_recv(ctx->control_sock, &list, sizeof(list));
if (ret_len == 0) {
fprintf(stderr, "[error] Remote side has closed connection\n");
ret = -1;
sessions_count = be32toh(list.sessions_count);
for (i = 0; i < sessions_count; i++) {
- do {
- ret_len = recv(ctx->control_sock, &lsession, sizeof(lsession), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_recv(ctx->control_sock, &lsession, sizeof(lsession));
if (ret_len == 0) {
fprintf(stderr, "[error] Remote side has closed connection\n");
ret = -1;
// rq.seek = htobe32(LTTNG_VIEWER_SEEK_BEGINNING);
rq.seek = htobe32(LTTNG_VIEWER_SEEK_LAST);
- do {
- ret_len = send(ctx->control_sock, &cmd, sizeof(cmd), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_send(ctx->control_sock, &cmd, sizeof(cmd));
if (ret_len < 0) {
perror("[error] Error sending cmd");
ret = ret_len;
}
assert(ret_len == sizeof(cmd));
- do {
- ret_len = send(ctx->control_sock, &rq, sizeof(rq), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_send(ctx->control_sock, &rq, sizeof(rq));
if (ret_len < 0) {
perror("[error] Error sending attach request");
ret = ret_len;
}
assert(ret_len == sizeof(rq));
- do {
- ret_len = recv(ctx->control_sock, &rp, sizeof(rp), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_recv(ctx->control_sock, &rp, sizeof(rp));
if (ret_len == 0) {
fprintf(stderr, "[error] Remote side has closed connection\n");
ret = -1;
ctx->session->streams = g_new0(struct lttng_live_viewer_stream,
ctx->session->stream_count);
for (i = 0; i < be32toh(rp.streams_count); i++) {
- do {
- ret_len = recv(ctx->control_sock, &stream, sizeof(stream), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_recv(ctx->control_sock, &stream, sizeof(stream));
if (ret_len == 0) {
fprintf(stderr, "[error] Remote side has closed connection\n");
ret = -1;
rq.offset = offset;
rq.len = htobe32(len);
- do {
- ret_len = send(ctx->control_sock, &cmd, sizeof(cmd), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_send(ctx->control_sock, &cmd, sizeof(cmd));
if (ret_len < 0) {
perror("[error] Error sending cmd");
ret = ret_len;
}
assert(ret_len == sizeof(cmd));
- do {
- ret_len = send(ctx->control_sock, &rq, sizeof(rq), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_send(ctx->control_sock, &rq, sizeof(rq));
if (ret_len < 0) {
perror("[error] Error sending get_data_packet request");
ret = ret_len;
}
assert(ret_len == sizeof(rq));
- do {
- ret_len = recv(ctx->control_sock, &rp, sizeof(rp), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_recv(ctx->control_sock, &rp, sizeof(rp));
if (ret_len == 0) {
fprintf(stderr, "[error] Remote side has closed connection\n");
ret = -1;
stream->mmap_size);
}
- do {
- ret_len = recv(ctx->control_sock,
- mmap_align_addr(pos->base_mma), len,
- MSG_WAITALL);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_recv(ctx->control_sock,
+ mmap_align_addr(pos->base_mma), len);
if (ret_len == 0) {
fprintf(stderr, "[error] Remote side has closed connection\n");
ret = -1;
cmd.data_size = sizeof(rq);
cmd.cmd_version = 0;
- do {
- ret_len = send(ctx->control_sock, &cmd, sizeof(cmd), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_send(ctx->control_sock, &cmd, sizeof(cmd));
if (ret_len < 0) {
perror("[error] Error sending cmd");
ret = ret_len;
}
assert(ret_len == sizeof(cmd));
- do {
- ret_len = send(ctx->control_sock, &rq, sizeof(rq), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_send(ctx->control_sock, &rq, sizeof(rq));
if (ret_len < 0) {
perror("[error] Error sending get_metadata request");
ret = ret_len;
}
assert(ret_len == sizeof(rq));
- do {
- ret_len = recv(ctx->control_sock, &rp, sizeof(rp), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_recv(ctx->control_sock, &rp, sizeof(rp));
if (ret_len == 0) {
fprintf(stderr, "[error] Remote side has closed connection\n");
ret = -1;
ret = -1;
goto error;
}
- do {
- ret_len = recv(ctx->control_sock, data, len, MSG_WAITALL);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_recv(ctx->control_sock, data, len);
if (ret_len == 0) {
fprintf(stderr, "[error] Remote side has closed connection\n");
ret = -1;
rq.stream_id = htobe64(viewer_stream->id);
retry:
- do {
- ret_len = send(ctx->control_sock, &cmd, sizeof(cmd), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_send(ctx->control_sock, &cmd, sizeof(cmd));
if (ret_len < 0) {
perror("[error] Error sending cmd");
ret = ret_len;
}
assert(ret_len == sizeof(cmd));
- do {
- ret_len = send(ctx->control_sock, &rq, sizeof(rq), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_send(ctx->control_sock, &rq, sizeof(rq));
if (ret_len < 0) {
perror("[error] Error sending get_next_index request");
ret = ret_len;
}
assert(ret_len == sizeof(rq));
- do {
- ret_len = recv(ctx->control_sock, &rp, sizeof(rp), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_recv(ctx->control_sock, &rp, sizeof(rp));
if (ret_len == 0) {
fprintf(stderr, "[error] Remote side has closed connection\n");
ret = -1;
cmd.data_size = 0;
cmd.cmd_version = 0;
- do {
- ret_len = send(ctx->control_sock, &cmd, sizeof(cmd), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_send(ctx->control_sock, &cmd, sizeof(cmd));
if (ret_len < 0) {
perror("[error] Error sending cmd");
ret = ret_len;
}
assert(ret_len == sizeof(cmd));
- do {
- ret_len = recv(ctx->control_sock, &resp, sizeof(resp), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_recv(ctx->control_sock, &resp, sizeof(resp));
if (ret_len == 0) {
fprintf(stderr, "[error] Remote side has closed connection\n");
ret = -1;
memset(&rq, 0, sizeof(rq));
rq.session_id = htobe64(id);
- do {
- ret_len = send(ctx->control_sock, &cmd, sizeof(cmd), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_send(ctx->control_sock, &cmd, sizeof(cmd));
if (ret_len < 0) {
perror("[error] Error sending cmd");
ret = ret_len;
}
assert(ret_len == sizeof(cmd));
- do {
- ret_len = send(ctx->control_sock, &rq, sizeof(rq), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_send(ctx->control_sock, &rq, sizeof(rq));
if (ret_len < 0) {
perror("[error] Error sending get_new_streams request");
ret = ret_len;
}
assert(ret_len == sizeof(rq));
- do {
- ret_len = recv(ctx->control_sock, &rp, sizeof(rp), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_recv(ctx->control_sock, &rp, sizeof(rp));
if (ret_len == 0) {
fprintf(stderr, "[error] Remote side has closed connection\n");
ret = -1;
ctx->session->streams = g_new0(struct lttng_live_viewer_stream,
ctx->session->stream_count);
for (i = 0; i < stream_count; i++) {
- do {
- ret_len = recv(ctx->control_sock, &stream, sizeof(stream), 0);
- } while (ret_len < 0 && errno == EINTR);
+ ret_len = lttng_live_recv(ctx->control_sock, &stream, sizeof(stream));
if (ret_len == 0) {
fprintf(stderr, "[error] Remote side has closed connection\n");
ret = -1;