From b6576dcd985225dee9cbd1e8ae2480e6f51fe555 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Fri, 12 Jan 2024 10:20:10 +0100 Subject: [PATCH] iiod: Add support for IIOD_OP_RETRY_DEQUEUE_BLOCK command During a previous IIOD_OP_TRANSFER_BLOCK command, if the enqueue succeeded but dequeue failed, the client cannot send the same command again, as it would try to enqueue again. Instead, it will send a IIOD_RETRY_DEQUEUE_BLOCK, which will only attempt to dequeue the block. Signed-off-by: Paul Cercueil --- iiod/responder.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/iiod/responder.c b/iiod/responder.c index a717483b2..621d08ce1 100644 --- a/iiod/responder.c +++ b/iiod/responder.c @@ -779,6 +779,41 @@ static void handle_transfer_block(struct parser_pdata *pdata, iiod_io_send_response_code(block_entry->io, ret); } +static void handle_retry_dequeue_block(struct parser_pdata *pdata, + const struct iiod_command *cmd, + struct iiod_command_data *cmd_data) +{ + struct buffer_entry *entry; + struct block_entry *block_entry; + struct iio_block *block; + struct iio_buffer *buf; + int ret; + + buf = get_iio_buffer(pdata, cmd, &entry); + ret = iio_err(buf); + if (ret) { + IIO_PERROR(ret, "handle_transfer_block: Could not find IIO buffer"); + return; + } + + block = get_iio_block(pdata, entry, cmd, &block_entry); + ret = iio_err(block); + if (ret) { + IIO_PERROR(ret, "handle_transfer_block: Could not find IIO block"); + return; + } + + ret = iio_task_enqueue_autoclear(entry->dequeue_task, block_entry); + if (ret) + goto out_send_response; + + /* The return code and/or data will be sent from the task handler. */ + return; + +out_send_response: + iiod_io_send_response_code(block_entry->io, ret); +} + static int evstream_read(void *priv, void *d) { struct evstream_entry *entry = priv; @@ -982,6 +1017,7 @@ static const iiod_opcode_fn iiod_op_functions[] = { [IIOD_OP_FREE_BLOCK] = handle_free_block, [IIOD_OP_TRANSFER_BLOCK] = handle_transfer_block, [IIOD_OP_ENQUEUE_BLOCK_CYCLIC] = handle_transfer_block, + [IIOD_OP_RETRY_DEQUEUE_BLOCK] = handle_retry_dequeue_block, [IIOD_OP_CREATE_EVSTREAM] = handle_create_evstream, [IIOD_OP_FREE_EVSTREAM] = handle_free_evstream,