From af63d87a76ef4ae010e230d86ce9c07c6081cb80 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 20 Feb 2019 17:12:34 +0100 Subject: Stream client: add disconnect callback It's similar to connect_cb() but called once client has been disconnected. Change-Id: I905adb2d6191216551a3bcdcd1aec1f96f01612a --- src/stream.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/stream.c') diff --git a/src/stream.c b/src/stream.c index 1880e25..c4db3d7 100644 --- a/src/stream.c +++ b/src/stream.c @@ -155,6 +155,7 @@ struct osmo_stream_cli { uint16_t local_port; uint16_t proto; int (*connect_cb)(struct osmo_stream_cli *srv); + int (*disconnect_cb)(struct osmo_stream_cli *srv); int (*read_cb)(struct osmo_stream_cli *srv); int (*write_cb)(struct osmo_stream_cli *srv); void *data; @@ -194,8 +195,11 @@ void osmo_stream_cli_close(struct osmo_stream_cli *cli) close(cli->ofd.fd); cli->ofd.fd = -1; - if (cli->state == STREAM_CLI_STATE_CONNECTED) + if (cli->state == STREAM_CLI_STATE_CONNECTED) { LOGSCLI(cli, LOGL_DEBUG, "connection closed\n"); + if (cli->disconnect_cb) + cli->disconnect_cb(cli); + } cli->state = STREAM_CLI_STATE_NONE; } @@ -442,6 +446,15 @@ osmo_stream_cli_set_connect_cb(struct osmo_stream_cli *cli, cli->connect_cb = connect_cb; } +/*! \brief Set the call-back function called on disconnect of the stream client socket + * \param[in] cli Stream Client to modify + * \param[in] disconnect_cb Call-back function to be called upon disconnect */ +void osmo_stream_cli_set_disconnect_cb(struct osmo_stream_cli *cli, + int (*disconnect_cb)(struct osmo_stream_cli *cli)) +{ + cli->disconnect_cb = disconnect_cb; +} + /*! \brief Set the call-back function called to read from the stream client socket * \param[in] cli Stream Client to modify * \param[in] read_cb Call-back function to be called when we want to read */ -- cgit v1.2.3