laforge submitted this change.
6 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
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
---
M examples/stream-client.c
M examples/stream-server.c
2 files changed, 34 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 @@
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 @@
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 @@
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 @@
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);
}
To view, visit change 36124. To unsubscribe, or for help writing mail filters, visit settings.