+int relayd_send_metadata(struct lttcomm_relayd_sock *rsock, size_t len)
+{
+ int ret;
+
+ /* Code flow error. Safety net. */
+ assert(rsock);
+
+ DBG("Relayd sending metadata of size %zu", len);
+
+ /* Send command */
+ ret = send_command(rsock, 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_relayd_sock.
+ */
+int relayd_connect(struct lttcomm_relayd_sock *rsock)
+{
+ /* Code flow error. Safety net. */
+ assert(rsock);
+
+ if (!rsock->sock.ops) {
+ /*
+ * Attempting a connect on a non-initialized socket.
+ */
+ return -ECONNRESET;
+ }
+
+ DBG3("Relayd connect ...");
+
+ return rsock->sock.ops->connect(&rsock->sock);
+}
+
+/*
+ * Close relayd socket with an allocated lttcomm_relayd_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_relayd_sock *rsock)
+{
+ int ret;
+
+ /* Code flow error. Safety net. */
+ assert(rsock);
+
+ /* An invalid fd is fine, return success. */
+ if (rsock->sock.fd < 0) {
+ ret = 0;
+ goto end;
+ }
+
+ DBG3("Relayd closing socket %d", rsock->sock.fd);
+
+ if (rsock->sock.ops) {
+ ret = rsock->sock.ops->close(&rsock->sock);
+ } else {
+ /* Default call if no specific ops found. */
+ ret = close(rsock->sock.fd);
+ if (ret < 0) {
+ PERROR("relayd_close default close");
+ }
+ }
+ rsock->sock.fd = -1;
+
+end:
+ return ret;
+}
+
+/*
+ * Send data header structure to the relayd.
+ */
+int relayd_send_data_hdr(struct lttcomm_relayd_sock *rsock,
+ struct lttcomm_relayd_data_hdr *hdr, size_t size)