+
+ /* 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.
+ */
+int relayd_close(struct lttcomm_sock *sock)
+{
+ /* Code flow error. Safety net. */
+ assert(sock);
+
+ DBG3("Relayd closing socket %d", sock->fd);
+
+ return sock->ops->close(sock);
+}
+
+/*
+ * 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)
+{
+ int ret;
+ struct lttcomm_relayd_close_stream msg;