diff options
author | Max <msuraev@sysmocom.de> | 2019-02-20 17:12:34 +0100 |
---|---|---|
committer | Max <msuraev@sysmocom.de> | 2019-02-20 17:33:32 +0100 |
commit | af63d87a76ef4ae010e230d86ce9c07c6081cb80 (patch) | |
tree | fa0106633f0016b0b9b5fb5644d729f6e1fd2492 /src | |
parent | fe3527da2ac691c961f767c97d70bfe00d1e4d10 (diff) |
Stream client: add disconnect callback
It's similar to connect_cb() but called once client has been
disconnected.
Change-Id: I905adb2d6191216551a3bcdcd1aec1f96f01612a
Diffstat (limited to 'src')
-rw-r--r-- | src/stream.c | 15 |
1 files changed, 14 insertions, 1 deletions
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 */ |