+int relayd_send_metadata(struct lttcomm_sock *sock, size_t len)
+{
+ int ret;
+
+ /* Code flow error. Safety net. */
+ assert(sock);
+
+ DBG("Relayd sending metadata of size %zu", len);
+
+ /* Send command */
+ ret = send_command(sock, RELAYD_SEND_METADATA, NULL, len, 0);
+ if (ret < 0) {
+ goto error;
+ }
+
+ DBG2("Relayd metadata added successfully");
+
+ /*
+ * After that call, the metadata data MUST be sent to the relayd so the
+ * receive size on the other end matches the len of the metadata packet
+ * header. This is why we don't wait for a reply here.
+ */
+
+error:
+ return ret;
+}
+
+/*
+ * Connect to relay daemon with an allocated lttcomm_sock.
+ */
+int relayd_connect(struct lttcomm_sock *sock)
+{
+ /* Code flow error. Safety net. */
+ assert(sock);
+
+ DBG3("Relayd connect ...");
+
+ return sock->ops->connect(sock);
+}
+
+/*
+ * Close relayd socket with an allocated lttcomm_sock.
+ *
+ * If no socket operations are found, simply return 0 meaning that everything
+ * is fine. Without operations, the socket can not possibly be opened or used.
+ * This is possible if the socket was allocated but not created. However, the
+ * caller could simply use it to store a valid file descriptor for instance
+ * passed over a Unix socket and call this to cleanup but still without a valid
+ * ops pointer.
+ *
+ * Return the close returned value. On error, a negative value is usually
+ * returned back from close(2).
+ */
+int relayd_close(struct lttcomm_sock *sock)
+{
+ int ret;
+
+ /* Code flow error. Safety net. */
+ assert(sock);
+
+ /* An invalid fd is fine, return success. */
+ if (sock->fd < 0) {
+ ret = 0;
+ goto end;
+ }
+
+ DBG3("Relayd closing socket %d", sock->fd);
+
+ if (sock->ops) {
+ ret = sock->ops->close(sock);
+ } else {
+ /* Default call if no specific ops found. */
+ ret = close(sock->fd);
+ if (ret < 0) {
+ PERROR("relayd_close default close");
+ }
+ }
+
+end:
+ return ret;
+}
+
+/*
+ * Send data header structure to the relayd.
+ */
+int relayd_send_data_hdr(struct lttcomm_sock *sock,
+ struct lttcomm_relayd_data_hdr *hdr, size_t size)
+{
+ int ret;
+
+ /* Code flow error. Safety net. */
+ assert(sock);
+ assert(hdr);
+
+ DBG3("Relayd sending data header of size %ld", size);
+
+ /* Again, safety net */
+ if (size == 0) {
+ size = sizeof(struct lttcomm_relayd_data_hdr);
+ }
+
+ /* Only send data header. */
+ ret = sock->ops->sendmsg(sock, hdr, size, 0);
+ if (ret < 0) {
+ ret = -errno;
+ goto error;
+ }
+
+ /*
+ * The data MUST be sent right after that command for the receive on the
+ * other end to match the size in the header.
+ */
+
+error:
+ return ret;
+}
+
+/*
+ * Send close stream command to the relayd.
+ */
+int relayd_send_close_stream(struct lttcomm_sock *sock, uint64_t stream_id,
+ uint64_t last_net_seq_num)