This commit adds support of waiter for poll(2) system call.
Below lines are examples to use this option: $ axfer transfer --waiter-type=poll -M -P -d 2 -D hw:0,3 /dev/urandom -f dat -vvv $ axfer transfer --waiter-type=poll -M -C -d 2 -D hw:1,0 /dev/null -r 48000 -vvv
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- axfer/Makefile.am | 3 ++- axfer/waiter-poll.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ axfer/waiter.c | 3 ++- axfer/waiter.h | 3 +++ 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 axfer/waiter-poll.c
diff --git a/axfer/Makefile.am b/axfer/Makefile.am index e425a28..7123006 100644 --- a/axfer/Makefile.am +++ b/axfer/Makefile.am @@ -50,4 +50,5 @@ axfer_SOURCES = \ subcmd-transfer.c \ xfer-libasound-irq-mmap.c \ waiter.h \ - waiter.c + waiter.c \ + waiter-poll.c diff --git a/axfer/waiter-poll.c b/axfer/waiter-poll.c new file mode 100644 index 00000000..61aa1a0 --- /dev/null +++ b/axfer/waiter-poll.c @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// waiter-poll.c - Waiter for event notification by poll(2). +// +// Copyright (c) 2018 Takashi Sakamoto o-takashi@sakamocchi.jp +// +// Licensed under the terms of the GNU General Public License, version 2. + +#include "waiter.h" +#include "misc.h" + +#include <stdlib.h> +#include <errno.h> +#include <poll.h> + +static int poll_prepare(struct waiter_context *waiter) +{ + // Nothing to do because an instance of waiter has required data. + return 0; +} + +static int poll_wait_event(struct waiter_context *waiter, int timeout_msec) +{ + int err; + + err = poll(waiter->pfds, waiter->pfd_count, timeout_msec); + if (err < 0) + return -errno; + + return err; +} + +static void poll_release(struct waiter_context *waiter) +{ + // Nothing to do because an instance of waiter has required data. + return; +} + +const struct waiter_data waiter_poll = { + .ops = { + .prepare = poll_prepare, + .wait_event = poll_wait_event, + .release = poll_release, + }, +}; diff --git a/axfer/waiter.c b/axfer/waiter.c index 0bc4740..446e617 100644 --- a/axfer/waiter.c +++ b/axfer/waiter.c @@ -16,6 +16,7 @@
static const char *const waiter_type_labels[] = { [WAITER_TYPE_DEFAULT] = "default", + [WAITER_TYPE_POLL] = "poll", };
enum waiter_type waiter_type_from_label(const char *label) @@ -42,7 +43,7 @@ int waiter_context_init(struct waiter_context *waiter, enum waiter_type type; const struct waiter_data *waiter; } entries[] = { - {WAITER_TYPE_COUNT, NULL}, + {WAITER_TYPE_POLL, &waiter_poll}, }; int i;
diff --git a/axfer/waiter.h b/axfer/waiter.h index 17e01cb..9366724 100644 --- a/axfer/waiter.h +++ b/axfer/waiter.h @@ -13,6 +13,7 @@
enum waiter_type { WAITER_TYPE_DEFAULT = 0, + WAITER_TYPE_POLL, WAITER_TYPE_COUNT, };
@@ -51,4 +52,6 @@ struct waiter_data { unsigned int private_size; };
+extern const struct waiter_data waiter_poll; + #endif