aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Sperling <ssperling@sysmocom.de>2018-02-22 17:13:57 +0100
committerStefan Sperling <ssperling@sysmocom.de>2018-02-22 17:13:57 +0100
commit253c8d06582e3e0a6899c98a398ee4d1a0cb69ab (patch)
tree1dba175006c8f6b2f9477d0a7b19ddb5a313ba07
parent2cbaf4139ae768ff5a79c79d389045b4ef4dd0e6 (diff)
allow osmo_stream_srv_send() to destroy the connectionstsp/destroy_conn_with_cb_flag
Carve a flags field out of the msgb control buffer and define a flag which causes the corresponding conncetion to be closed after this message buffer has been transmited. Change-Id: I7fb848d5b5cca18381df2e8f34192c183eb4bc84
-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);
}