aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/osmocom/netif/stream.h12
-rw-r--r--src/stream.c12
2 files changed, 24 insertions, 0 deletions
diff --git a/include/osmocom/netif/stream.h b/include/osmocom/netif/stream.h
index 4e1beb6..e05ec2b 100644
--- a/include/osmocom/netif/stream.h
+++ b/include/osmocom/netif/stream.h
@@ -8,6 +8,18 @@
* @{
*/
+/*! \brief Access flags field in the msgb control buffer */
+#define msgb_netif_flags(msg) (msg)->cb[0]
+
+/*! \brief Message buffer flag: Destroy a stream after sending this message. */
+#define MSGB_NETIF_FLAG_TX_STREAM_DESTROY 0x00000001
+
+/*! \brief Mark a message buffer as the final message to be transmitted on a stream.
+ * The stream will be destroyed after this message has been sent, i.e. either
+ * osmo_stream_cli_destroy() or osmo_stream_srv_destroy() will be called on the
+ * corresponding connection. */
+void msgb_netif_destroy_conn_after_tx(struct msgb *msg);
+
/*! \brief Access the SCTP PPID from the msgb control buffer */
#define msgb_sctp_ppid(msg) (msg)->cb[3]
/*! \brief Access the SCTP Stream ID from the msgb control buffer */
diff --git a/src/stream.c b/src/stream.c
index 8a1be38..b8ee7b9 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -119,6 +119,10 @@ static int setsockopt_nodelay(int fd, int proto, int on)
return rc;
}
+void msgb_netif_destroy_conn_after_tx(struct msgb *msg)
+{
+ msgb_netif_flags(msg) |= MSGB_NETIF_FLAG_TX_STREAM_DESTROY;
+}
/*
* Client side.
@@ -237,6 +241,10 @@ static int osmo_stream_cli_write(struct osmo_stream_cli *cli)
}
LOGP(DLINP, LOGL_ERROR, "error to send\n");
}
+
+ if (msgb_netif_flags(msg) & MSGB_NETIF_FLAG_TX_STREAM_DESTROY)
+ osmo_stream_cli_destroy(cli);
+
msgb_free(msg);
return 0;
}
@@ -828,6 +836,10 @@ static void osmo_stream_srv_write(struct osmo_stream_srv *conn)
if (ret < 0) {
LOGP(DLINP, LOGL_ERROR, "error to send\n");
}
+
+ if (msgb_netif_flags(msg) & MSGB_NETIF_FLAG_TX_STREAM_DESTROY)
+ osmo_stream_srv_destroy(conn);
+
msgb_free(msg);
}