+++ /dev/null
-#ifndef _BABELTRACE_COMPAT_SEND_H
-#define _BABELTRACE_COMPAT_SEND_H
-
-/*
- * babeltrace/compat/send.h
- *
- * Copyright (C) 2015 Michael Jeanson <mjeanson@efficios.com>
- * 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-/*
- * This wrapper is used on platforms that have no way of ignoring SIGPIPE
- * during a send().
- */
-
-#ifndef MSG_NOSIGNAL
-# ifdef SO_NOSIGPIPE
-# define MSG_NOSIGNAL SO_NOSIGPIPE
-# endif
-#endif
-
-#if defined(MSG_NOSIGNAL)
-static inline
-ssize_t bt_send_nosigpipe(int fd, const void *buffer, size_t size)
-{
- return send(fd, buffer, size, MSG_NOSIGNAL);
-}
-#else
-
-#include <signal.h>
-
-static inline
-ssize_t bt_send_nosigpipe(int fd, const void *buffer, size_t size)
-{
- ssize_t sent;
- int saved_err;
- sigset_t sigpipe_set, pending_set, old_set;
- int sigpipe_was_pending;
-
- /*
- * Discard the SIGPIPE from send(), not disturbing any SIGPIPE
- * that might be already pending. If a bogus SIGPIPE is sent to
- * the entire process concurrently by a malicious user, it may
- * be simply discarded.
- */
- if (sigemptyset(&pending_set)) {
- return -1;
- }
- /*
- * sigpending returns the mask of signals that are _both_
- * blocked for the thread _and_ pending for either the thread or
- * the entire process.
- */
- if (sigpending(&pending_set)) {
- return -1;
- }
- sigpipe_was_pending = sigismember(&pending_set, SIGPIPE);
- /*
- * If sigpipe was pending, it means it was already blocked, so
- * no need to block it.
- */
- if (!sigpipe_was_pending) {
- if (sigemptyset(&sigpipe_set)) {
- return -1;
- }
- if (sigaddset(&sigpipe_set, SIGPIPE)) {
- return -1;
- }
- if (pthread_sigmask(SIG_BLOCK, &sigpipe_set, &old_set)) {
- return -1;
- }
- }
-
- /* Send and save errno. */
- sent = send(fd, buffer, size, 0);
- saved_err = errno;
-
- if (sent == -1 && errno == EPIPE && !sigpipe_was_pending) {
- struct timespec timeout = { 0, 0 };
- int ret;
-
- do {
- ret = sigtimedwait(&sigpipe_set, NULL,
- &timeout);
- } while (ret == -1 && errno == EINTR);
- }
- if (!sigpipe_was_pending) {
- if (pthread_sigmask(SIG_SETMASK, &old_set, NULL)) {
- return -1;
- }
- }
- /* Restore send() errno */
- errno = saved_err;
-
- return sent;
-}
-#endif
-
-#endif /* _BABELTRACE_COMPAT_SEND_H */
--- /dev/null
+#ifndef _BABELTRACE_COMPAT_SOCKET_H
+#define _BABELTRACE_COMPAT_SOCKET_H
+
+/*
+ * babeltrace/compat/socket.h
+ *
+ * Copyright (C) 2015-2017 Michael Jeanson <mjeanson@efficios.com>
+ * 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifdef __MINGW32__
+
+#include <winsock2.h>
+
+#define BT_INVALID_SOCKET INVALID_SOCKET
+#define BT_SOCKET_ERROR SOCKET_ERROR
+#define BT_SOCKET SOCKET
+
+static inline
+int bt_socket_init(void)
+{
+ WORD verreq;
+ WSADATA wsa;
+ int ret;
+
+ /* Request winsock 2.2 support */
+ verreq = MAKEWORD(2, 2);
+
+ ret = WSAStartup(verreq, &wsa);
+ if (ret != 0) {
+ BT_LOGE("Winsock init failed with error: %d", ret);
+ goto end;
+ }
+
+ if (LOBYTE(wsa.wVersion) != 2 || HIBYTE(wsa.wVersion) != 2) {
+ BT_LOGE_STR("Could not init winsock 2.2 support");
+ WSACleanup();
+ ret = -1;
+ }
+
+end:
+ return ret;
+}
+
+static inline
+int bt_socket_fini(void)
+{
+ return WSACleanup();
+}
+
+static inline
+int bt_socket_send(int sockfd, const void *buf, size_t len, int flags)
+{
+ return send(sockfd, buf, len, flags);
+}
+
+static inline
+int bt_socket_recv(int sockfd, void *buf, size_t len, int flags)
+{
+ return recv(sockfd, buf, len, flags);
+}
+
+static inline
+int bt_socket_close(int fd)
+{
+ return closesocket(fd);
+}
+
+static inline
+bool bt_socket_interrupted(void)
+{
+ /* There is no equivalent to EINTR in winsock 2.2 */
+ return false;
+}
+
+static inline
+const char *bt_socket_errormsg(void)
+{
+ const char *errstr;
+ int error = WSAGetLastError();
+
+ switch (error) {
+ case WSAEINTR:
+ errstr = "Call interrupted";
+ break;
+ case WSAEBADF:
+ errstr = "Bad file";
+ break;
+ case WSAEACCES:
+ errstr = "Bad access";
+ break;
+ case WSAEFAULT:
+ errstr = "Bad argument";
+ break;
+ case WSAEINVAL:
+ errstr = "Invalid arguments";
+ break;
+ case WSAEMFILE:
+ errstr = "Out of file descriptors";
+ break;
+ case WSAEWOULDBLOCK:
+ errstr = "Call would block";
+ break;
+ case WSAEINPROGRESS:
+ case WSAEALREADY:
+ errstr = "Blocking call in progress";
+ break;
+ case WSAENOTSOCK:
+ errstr = "Descriptor is not a socket";
+ break;
+ case WSAEDESTADDRREQ:
+ errstr = "Need destination address";
+ break;
+ case WSAEMSGSIZE:
+ errstr = "Bad message size";
+ break;
+ case WSAEPROTOTYPE:
+ errstr = "Bad protocol";
+ break;
+ case WSAENOPROTOOPT:
+ errstr = "Protocol option is unsupported";
+ break;
+ case WSAEPROTONOSUPPORT:
+ errstr = "Protocol is unsupported";
+ break;
+ case WSAESOCKTNOSUPPORT:
+ errstr = "Socket is unsupported";
+ break;
+ case WSAEOPNOTSUPP:
+ errstr = "Operation not supported";
+ break;
+ case WSAEAFNOSUPPORT:
+ errstr = "Address family not supported";
+ break;
+ case WSAEPFNOSUPPORT:
+ errstr = "Protocol family not supported";
+ break;
+ case WSAEADDRINUSE:
+ errstr = "Address already in use";
+ break;
+ case WSAEADDRNOTAVAIL:
+ errstr = "Address not available";
+ break;
+ case WSAENETDOWN:
+ errstr = "Network down";
+ break;
+ case WSAENETUNREACH:
+ errstr = "Network unreachable";
+ break;
+ case WSAENETRESET:
+ errstr = "Network has been reset";
+ break;
+ case WSAECONNABORTED:
+ errstr = "Connection was aborted";
+ break;
+ case WSAECONNRESET:
+ errstr = "Connection was reset";
+ break;
+ case WSAENOBUFS:
+ errstr = "No buffer space";
+ break;
+ case WSAEISCONN:
+ errstr = "Socket is already connected";
+ break;
+ case WSAENOTCONN:
+ errstr = "Socket is not connected";
+ break;
+ case WSAESHUTDOWN:
+ errstr = "Socket has been shut down";
+ break;
+ case WSAETOOMANYREFS:
+ errstr = "Too many references";
+ break;
+ case WSAETIMEDOUT:
+ errstr = "Timed out";
+ break;
+ case WSAECONNREFUSED:
+ errstr = "Connection refused";
+ break;
+ case WSAELOOP:
+ errstr = "Loop??";
+ break;
+ case WSAENAMETOOLONG:
+ errstr = "Name too long";
+ break;
+ case WSAEHOSTDOWN:
+ errstr = "Host down";
+ break;
+ case WSAEHOSTUNREACH:
+ errstr = "Host unreachable";
+ break;
+ case WSAENOTEMPTY:
+ errstr = "Not empty";
+ break;
+ case WSAEPROCLIM:
+ errstr = "Process limit reached";
+ break;
+ case WSAEUSERS:
+ errstr = "Too many users";
+ break;
+ case WSAEDQUOT:
+ errstr = "Bad quota";
+ break;
+ case WSAESTALE:
+ errstr = "Something is stale";
+ break;
+ case WSAEREMOTE:
+ errstr = "Remote error";
+ break;
+ case WSAEDISCON:
+ errstr = "Disconnected";
+ break;
+
+ /* Extended Winsock errors */
+ case WSASYSNOTREADY:
+ errstr = "Winsock library is not ready";
+ break;
+ case WSANOTINITIALISED:
+ errstr = "Winsock library not initialised";
+ break;
+ case WSAVERNOTSUPPORTED:
+ errstr = "Winsock version not supported";
+ break;
+
+ /* getXbyY() errors (already handled in herrmsg):
+ * Authoritative Answer: Host not found */
+ case WSAHOST_NOT_FOUND:
+ errstr = "Host not found";
+ break;
+
+ /* Non-Authoritative: Host not found, or SERVERFAIL */
+ case WSATRY_AGAIN:
+ errstr = "Host not found, try again";
+ break;
+
+ /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
+ case WSANO_RECOVERY:
+ errstr = "Unrecoverable error in call to nameserver";
+ break;
+
+ /* Valid name, no data record of requested type */
+ case WSANO_DATA:
+ errstr = "No data record of requested type";
+ break;
+
+ default:
+ errstr = "Unknown error";
+ }
+
+ return errstr;
+}
+
+#else /* __MINGW32__ */
+
+#include <unistd.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+
+#define BT_INVALID_SOCKET -1
+#define BT_SOCKET_ERROR -1
+#define BT_SOCKET int
+
+static inline
+int bt_socket_init(void)
+{
+ return 0;
+}
+
+static inline
+int bt_socket_fini(void)
+{
+ return 0;
+}
+
+static inline
+int bt_socket_send(int sockfd, const void *buf, size_t len, int flags)
+{
+ return send(sockfd, buf, len, flags);
+}
+
+static inline
+int bt_socket_recv(int sockfd, void *buf, size_t len, int flags)
+{
+ return recv(sockfd, buf, len, flags);
+}
+
+static inline
+int bt_socket_close(int fd)
+{
+ return close(fd);
+}
+
+static inline
+bool bt_socket_interrupted(void)
+{
+ return (errno == EINTR);
+}
+
+static inline
+const char *bt_socket_errormsg(void)
+{
+ return g_strerror(errno);
+}
+#endif
+
+
+/*
+ * This wrapper is used on platforms that have no way of ignoring SIGPIPE
+ * during a send().
+ */
+
+#ifndef MSG_NOSIGNAL
+# ifdef SO_NOSIGPIPE
+# define MSG_NOSIGNAL SO_NOSIGPIPE
+# elif defined(__MINGW32__)
+# define MSG_NOSIGNAL 0
+# endif
+#endif
+
+#if defined(MSG_NOSIGNAL)
+static inline
+ssize_t bt_socket_send_nosigpipe(int fd, const void *buffer, size_t size)
+{
+ return bt_socket_send(fd, buffer, size, MSG_NOSIGNAL);
+}
+#else
+
+#include <signal.h>
+
+static inline
+ssize_t bt_socket_send_nosigpipe(int fd, const void *buffer, size_t size)
+{
+ ssize_t sent;
+ int saved_err;
+ sigset_t sigpipe_set, pending_set, old_set;
+ int sigpipe_was_pending;
+
+ /*
+ * Discard the SIGPIPE from send(), not disturbing any SIGPIPE
+ * that might be already pending. If a bogus SIGPIPE is sent to
+ * the entire process concurrently by a malicious user, it may
+ * be simply discarded.
+ */
+ if (sigemptyset(&pending_set)) {
+ return -1;
+ }
+ /*
+ * sigpending returns the mask of signals that are _both_
+ * blocked for the thread _and_ pending for either the thread or
+ * the entire process.
+ */
+ if (sigpending(&pending_set)) {
+ return -1;
+ }
+ sigpipe_was_pending = sigismember(&pending_set, SIGPIPE);
+ /*
+ * If sigpipe was pending, it means it was already blocked, so
+ * no need to block it.
+ */
+ if (!sigpipe_was_pending) {
+ if (sigemptyset(&sigpipe_set)) {
+ return -1;
+ }
+ if (sigaddset(&sigpipe_set, SIGPIPE)) {
+ return -1;
+ }
+ if (pthread_sigmask(SIG_BLOCK, &sigpipe_set, &old_set)) {
+ return -1;
+ }
+ }
+
+ /* Send and save errno. */
+ sent = bt_socket_send(fd, buffer, size, 0);
+ saved_err = errno;
+
+ if (sent == -1 && errno == EPIPE && !sigpipe_was_pending) {
+ struct timespec timeout = { 0, 0 };
+ int ret;
+
+ do {
+ ret = sigtimedwait(&sigpipe_set, NULL,
+ &timeout);
+ } while (ret == -1 && errno == EINTR);
+ }
+ if (!sigpipe_was_pending) {
+ if (pthread_sigmask(SIG_SETMASK, &old_set, NULL)) {
+ return -1;
+ }
+ }
+ /* Restore send() errno */
+ errno = saved_err;
+
+ return sent;
+}
+#endif
+
+
+#endif /* _BABELTRACE_COMPAT_SOCKET_H */
#include <unistd.h>
#include <glib.h>
#include <inttypes.h>
-#include <sys/socket.h>
#include <sys/types.h>
-#include <netinet/in.h>
-#include <netdb.h>
#include <fcntl.h>
-#include <poll.h>
-#include <babeltrace/compat/send-internal.h>
+#include <babeltrace/compat/socket-internal.h>
+#include <babeltrace/endian-internal.h>
#include <babeltrace/compiler-internal.h>
#include <babeltrace/common-internal.h>
#include <babeltrace/graph/graph.h>
size_t copied = 0, to_copy = len;
struct lttng_live_component *lttng_live =
viewer_connection->lttng_live;
- int fd = viewer_connection->control_sock;
+ BT_SOCKET sock = viewer_connection->control_sock;
do {
- ret = recv(fd, buf + copied, to_copy, 0);
+ ret = bt_socket_recv(sock, buf + copied, to_copy, 0);
if (ret > 0) {
assert(ret <= to_copy);
copied += ret;
to_copy -= ret;
}
- if (ret < 0 && errno == EINTR) {
+ if (ret == BT_SOCKET_ERROR && bt_socket_interrupted()) {
if (lttng_live_is_canceled(lttng_live)) {
break;
} else {
} while (ret > 0 && to_copy > 0);
if (ret > 0)
ret = copied;
- /* ret = 0 means orderly shutdown, ret < 0 is error. */
+ /* ret = 0 means orderly shutdown, ret == BT_SOCKET_ERROR is error. */
return ret;
}
{
struct lttng_live_component *lttng_live =
viewer_connection->lttng_live;
- int fd = viewer_connection->control_sock;
+ BT_SOCKET sock = viewer_connection->control_sock;
ssize_t ret;
for (;;) {
- ret = bt_send_nosigpipe(fd, buf, len);
- if (ret < 0 && errno == EINTR) {
+ ret = bt_socket_send_nosigpipe(sock, buf, len);
+ if (ret == BT_SOCKET_ERROR && bt_socket_interrupted()) {
if (lttng_live_is_canceled(lttng_live)) {
break;
} else {
connect.type = htobe32(LTTNG_VIEWER_CLIENT_COMMAND);
ret_len = lttng_live_send(viewer_connection, &cmd, sizeof(cmd));
- if (ret_len < 0) {
- BT_LOGE("Error sending cmd: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error sending cmd: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(cmd));
ret_len = lttng_live_send(viewer_connection, &connect, sizeof(connect));
- if (ret_len < 0) {
- BT_LOGE("Error sending version: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error sending version: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(connect));
BT_LOGI("Remote side has closed connection");
goto error;
}
- if (ret_len < 0) {
- BT_LOGE("Error receiving version: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error receiving version: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(connect));
goto error;
}
- if ((viewer_connection->control_sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
- BT_LOGE("Socket creation failed: %s", strerror(errno));
+ if ((viewer_connection->control_sock = socket(AF_INET, SOCK_STREAM, 0)) == BT_INVALID_SOCKET) {
+ BT_LOGE("Socket creation failed: %s", bt_socket_errormsg());
goto error;
}
memset(&(server_addr.sin_zero), 0, 8);
if (connect(viewer_connection->control_sock, (struct sockaddr *) &server_addr,
- sizeof(struct sockaddr)) == -1) {
- BT_LOGE("Connection failed: %s", strerror(errno));
+ sizeof(struct sockaddr)) == BT_SOCKET_ERROR) {
+ BT_LOGE("Connection failed: %s", bt_socket_errormsg());
goto error;
}
if (lttng_live_handshake(viewer_connection)) {
return ret;
error:
- if (viewer_connection->control_sock >= 0) {
- if (close(viewer_connection->control_sock)) {
- BT_LOGE("Close: %s", strerror(errno));
+ if (viewer_connection->control_sock != BT_INVALID_SOCKET) {
+ if (bt_socket_close(viewer_connection->control_sock) == BT_SOCKET_ERROR) {
+ BT_LOGE("Close: %s", bt_socket_errormsg());
}
}
- viewer_connection->control_sock = -1;
+ viewer_connection->control_sock = BT_INVALID_SOCKET;
return -1;
}
static void lttng_live_disconnect_viewer(struct bt_live_viewer_connection *viewer_connection)
{
- if (viewer_connection->control_sock < 0) {
+ if (viewer_connection->control_sock == BT_INVALID_SOCKET) {
return;
}
- if (close(viewer_connection->control_sock)) {
- BT_LOGE("Close: %s", strerror(errno));
- viewer_connection->control_sock = -1;
+ if (bt_socket_close(viewer_connection->control_sock) == BT_SOCKET_ERROR) {
+ BT_LOGE("Close: %s", bt_socket_errormsg());
+ viewer_connection->control_sock = BT_INVALID_SOCKET;
}
}
cmd.cmd_version = htobe32(0);
ret_len = lttng_live_send(viewer_connection, &cmd, sizeof(cmd));
- if (ret_len < 0) {
- BT_LOGE("Error sending cmd: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error sending cmd: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(cmd));
BT_LOGI("Remote side has closed connection");
goto error;
}
- if (ret_len < 0) {
- BT_LOGE("Error receiving session list: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error receiving session list: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(list));
BT_LOGI("Remote side has closed connection");
goto error;
}
- if (ret_len < 0) {
- BT_LOGE("Error receiving session: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error receiving session: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(lsession));
cmd.cmd_version = htobe32(0);
ret_len = lttng_live_send(viewer_connection, &cmd, sizeof(cmd));
- if (ret_len < 0) {
- BT_LOGE("Error sending cmd: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error sending cmd: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(cmd));
BT_LOGI("Remote side has closed connection");
goto error;
}
- if (ret_len < 0) {
- BT_LOGE("Error receiving session list: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error receiving session list: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(list));
BT_LOGI("Remote side has closed connection");
goto error;
}
- if (ret_len < 0) {
- BT_LOGE("Error receiving session: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error receiving session: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(lsession));
if ((strncmp(lsession.session_name,
viewer_connection->session_name->str,
- MAXNAMLEN) == 0) && (strncmp(lsession.hostname,
+ LTTNG_VIEWER_NAME_MAX) == 0) && (strncmp(lsession.hostname,
viewer_connection->target_hostname->str,
- MAXNAMLEN) == 0)) {
+ LTTNG_VIEWER_HOST_NAME_MAX) == 0)) {
if (lttng_live_add_session(lttng_live, session_id,
lsession.hostname,
lsession.session_name)) {
cmd.cmd_version = htobe32(0);
ret_len = lttng_live_send(viewer_connection, &cmd, sizeof(cmd));
- if (ret_len < 0) {
- BT_LOGE("Error sending cmd: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error sending cmd: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(cmd));
BT_LOGI("Remote side has closed connection");
goto error;
}
- if (ret_len < 0) {
- BT_LOGE("Error receiving create session reply: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error receiving create session reply: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(resp));
BT_LOGI("Remote side has closed connection");
goto error;
}
- if (ret_len < 0) {
+ if (ret_len == BT_SOCKET_ERROR) {
BT_LOGE("Error receiving stream");
goto error;
}
rq.seek = htobe32(LTTNG_VIEWER_SEEK_LAST);
ret_len = lttng_live_send(viewer_connection, &cmd, sizeof(cmd));
- if (ret_len < 0) {
- BT_LOGE("Error sending cmd: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error sending cmd: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(cmd));
ret_len = lttng_live_send(viewer_connection, &rq, sizeof(rq));
- if (ret_len < 0) {
- BT_LOGE("Error sending attach request: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error sending attach request: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(rq));
BT_LOGI("Remote side has closed connection");
goto error;
}
- if (ret_len < 0) {
- BT_LOGE("Error receiving attach response: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error receiving attach response: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(rp));
rq.session_id = htobe64(session_id);
ret_len = lttng_live_send(viewer_connection, &cmd, sizeof(cmd));
- if (ret_len < 0) {
- BT_LOGE("Error sending cmd: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error sending cmd: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(cmd));
ret_len = lttng_live_send(viewer_connection, &rq, sizeof(rq));
- if (ret_len < 0) {
- BT_LOGE("Error sending detach request: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error sending detach request: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(rq));
BT_LOGI("Remote side has closed connection");
goto error;
}
- if (ret_len < 0) {
- BT_LOGE("Error receiving detach response: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error receiving detach response: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(rp));
cmd.cmd_version = htobe32(0);
ret_len = lttng_live_send(viewer_connection, &cmd, sizeof(cmd));
- if (ret_len < 0) {
- BT_LOGE("Error sending cmd: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error sending cmd: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(cmd));
ret_len = lttng_live_send(viewer_connection, &rq, sizeof(rq));
- if (ret_len < 0) {
- BT_LOGE("Error sending get_metadata request: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error sending get_metadata request: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(rq));
BT_LOGI("Remote side has closed connection");
goto error;
}
- if (ret_len < 0) {
- BT_LOGE("Error receiving get_metadata response: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error receiving get_metadata response: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(rp));
BT_LOGI("Remote side has closed connection");
goto error_free_data;
}
- if (ret_len < 0) {
- BT_LOGE("Error receiving trace packet: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error receiving trace packet: %s", bt_socket_errormsg());
goto error_free_data;
}
assert(ret_len == len);
rq.stream_id = htobe64(stream->viewer_stream_id);
ret_len = lttng_live_send(viewer_connection, &cmd, sizeof(cmd));
- if (ret_len < 0) {
- BT_LOGE("Error sending cmd: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error sending cmd: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(cmd));
ret_len = lttng_live_send(viewer_connection, &rq, sizeof(rq));
- if (ret_len < 0) {
- BT_LOGE("Error sending get_next_index request: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error sending get_next_index request: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(rq));
BT_LOGI("Remote side has closed connection");
goto error;
}
- if (ret_len < 0) {
- BT_LOGE("Error receiving get_next_index response: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error receiving get_next_index response: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(rp));
rq.len = htobe32(req_len);
ret_len = lttng_live_send(viewer_connection, &cmd, sizeof(cmd));
- if (ret_len < 0) {
- BT_LOGE("Error sending cmd: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error sending cmd: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(cmd));
ret_len = lttng_live_send(viewer_connection, &rq, sizeof(rq));
- if (ret_len < 0) {
- BT_LOGE("Error sending get_data request: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error sending get_data request: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(rq));
BT_LOGI("Remote side has closed connection");
goto error;
}
- if (ret_len < 0) {
- BT_LOGE("Error receiving get_data response: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error receiving get_data response: %s", bt_socket_errormsg());
goto error;
}
if (ret_len != sizeof(rp)) {
BT_LOGI("Remote side has closed connection");
goto error;
}
- if (ret_len < 0) {
- BT_LOGE("Error receiving trace packet: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error receiving trace packet: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == req_len);
rq.session_id = htobe64(session->id);
ret_len = lttng_live_send(viewer_connection, &cmd, sizeof(cmd));
- if (ret_len < 0) {
- BT_LOGE("Error sending cmd: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error sending cmd: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(cmd));
ret_len = lttng_live_send(viewer_connection, &rq, sizeof(rq));
- if (ret_len < 0) {
- BT_LOGE("Error sending get_new_streams request: %s", strerror(errno));
+ if (ret_len == BT_SOCKET_ERROR) {
+ BT_LOGE("Error sending get_new_streams request: %s", bt_socket_errormsg());
goto error;
}
assert(ret_len == sizeof(rq));
BT_LOGI("Remote side has closed connection");
goto error;
}
- if (ret_len < 0) {
+ if (ret_len == BT_SOCKET_ERROR) {
BT_LOGE("Error receiving get_new_streams response");
goto error;
}
viewer_connection = g_new0(struct bt_live_viewer_connection, 1);
+ if (bt_socket_init() != 0) {
+ goto error;
+ }
+
bt_object_init(&viewer_connection->obj, connection_release);
- viewer_connection->control_sock = -1;
+ viewer_connection->control_sock = BT_INVALID_SOCKET;
viewer_connection->port = -1;
viewer_connection->lttng_live = lttng_live;
viewer_connection->url = g_string_new(url);
g_string_free(viewer_connection->session_name, TRUE);
}
g_free(viewer_connection);
+
+ bt_socket_fini();
}