From 253c8d06582e3e0a6899c98a398ee4d1a0cb69ab Mon Sep 17 00:00:00 2001 From: Stefan Sperling Date: Thu, 22 Feb 2018 17:13:57 +0100 Subject: allow osmo_stream_srv_send() to destroy the connection 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 --- include/osmocom/netif/stream.h | 12 ++++++++++++ src/stream.c | 12 ++++++++++++ 2 files changed, 24 insertions(+) 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); } -- cgit v1.2.3