aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2024-02-28 09:57:41 +0100
committerAndreas Eversberg <jolly@eversberg.eu>2024-03-07 10:28:20 +0100
commitb06e63b7c713008358d20cf0cf779713bd59b583 (patch)
treeb51e46c8442d39a41eb8d99ce1dc7ede0da2f44e
parente1153bcd376250843a1b13984f458e37a0ed4136 (diff)
stream_{client,server} example: Cleanup on exit
In order to detect memory leaks while debugging, stream server/client and keyboard is closed on exit. Related: OS#5753 Change-Id: I9dbb7f46b2a798e88ad4df8ff73c6ee40c07b843
-rw-r--r--examples/stream-client.c13
-rw-r--r--examples/stream-server.c12
2 files changed, 21 insertions, 4 deletions
diff --git a/examples/stream-client.c b/examples/stream-client.c
index 97aaa1c..cae0153 100644
--- a/examples/stream-client.c
+++ b/examples/stream-client.c
@@ -32,10 +32,13 @@ const struct log_info osmo_stream_cli_test_log_info = {
static struct osmo_stream_cli *conn;
+static bool quit = false;
+
void sighandler(int foo)
{
LOGP(DSTREAMTEST, LOGL_NOTICE, "closing stream.\n");
- exit(EXIT_SUCCESS);
+ quit = true;
+ signal(SIGINT, SIG_DFL);
}
static int connect_cb(struct osmo_stream_cli *conn)
@@ -162,9 +165,15 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
+ signal(SIGINT, sighandler);
+
LOGP(DSTREAMTEST, LOGL_NOTICE, "Entering main loop\n");
- while(1) {
+ while (!quit) {
osmo_select_main(0);
}
+
+ osmo_fd_unregister(kbd_ofd);
+
+ osmo_stream_cli_destroy(conn);
}
diff --git a/examples/stream-server.c b/examples/stream-server.c
index d0647b7..f6332dc 100644
--- a/examples/stream-server.c
+++ b/examples/stream-server.c
@@ -35,11 +35,13 @@ const struct log_info osmo_stream_srv_test_log_info = {
static struct osmo_stream_srv_link *srv;
static struct osmo_stream_srv *conn;
+bool quit = false;
void sighandler(int foo)
{
LOGP(DSTREAMTEST, LOGL_NOTICE, "closing STREAMSERVER.\n");
- exit(EXIT_SUCCESS);
+ quit = true;
+ signal(SIGINT, SIG_DFL);
}
int read_cb(struct osmo_stream_srv *conn, struct msgb *msg)
@@ -181,9 +183,15 @@ int main(int argc, char **argv)
osmo_fd_setup(kbd_ofd, STDIN_FILENO, OSMO_FD_READ, kbd_cb, srv, 0);
osmo_fd_register(kbd_ofd);
+ signal(SIGINT, sighandler);
+
LOGP(DSTREAMTEST, LOGL_NOTICE, "Entering main loop on %s\n", osmo_stream_srv_link_get_sockname(srv));
- while(1) {
+ while (!quit) {
osmo_select_main(0);
}
+
+ osmo_fd_unregister(kbd_ofd);
+
+ osmo_stream_srv_link_destroy(srv);
}