From ce985def734aeb394d24652bf18ebcfcf8750fdf Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Tue, 4 Jun 2024 08:44:12 -0400 Subject: [PATCH] loop: clarify the pw_main_loop_run returned value --- doc/examples/tutorial3.c | 4 +++- src/pipewire/main-loop.c | 3 +++ src/pipewire/main-loop.h | 5 ++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/doc/examples/tutorial3.c b/doc/examples/tutorial3.c index 17c0ee445..6470740b3 100644 --- a/doc/examples/tutorial3.c +++ b/doc/examples/tutorial3.c @@ -29,12 +29,14 @@ static void roundtrip(struct pw_core *core, struct pw_main_loop *loop) struct roundtrip_data d = { .loop = loop }; struct spa_hook core_listener; + int err; pw_core_add_listener(core, &core_listener, &core_events, &d); d.pending = pw_core_sync(core, PW_ID_CORE, 0); - pw_main_loop_run(loop); + if ((err = pw_main_loop_run(loop)) < 0) + printf("main_loop_run error:%d!\n", err); spa_hook_remove(&core_listener); } diff --git a/src/pipewire/main-loop.c b/src/pipewire/main-loop.c index 15f246c79..6e73a13cb 100644 --- a/src/pipewire/main-loop.c +++ b/src/pipewire/main-loop.c @@ -135,5 +135,8 @@ int pw_main_loop_run(struct pw_main_loop *loop) } } pw_loop_leave(loop->loop); + + if (res > 0) // This is the number of fds last polled, not useful for the caller. + res = 0; return res; } diff --git a/src/pipewire/main-loop.h b/src/pipewire/main-loop.h index 78ab644e6..859695a2e 100644 --- a/src/pipewire/main-loop.h +++ b/src/pipewire/main-loop.h @@ -49,7 +49,10 @@ struct pw_loop * pw_main_loop_get_loop(struct pw_main_loop *loop); /** Destroy a loop */ void pw_main_loop_destroy(struct pw_main_loop *loop); -/** Run a main loop. This blocks until \ref pw_main_loop_quit is called */ +/** Run a main loop. This blocks until \ref pw_main_loop_quit is called. + * + * @return 0 on success, otherwise a negative number. + */ int pw_main_loop_run(struct pw_main_loop *loop); /** Quit a main loop */