From 0b71442dba5a62b4483e3406653677bab0fcf38c Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Mon, 26 Dec 2022 14:24:15 +0900 Subject: [PATCH] include/uipc: Remove timeout logic from uipc_endpoint_recv() The function `uipc_endpoint_recv()' contains logic to handle timeouts during message reception, even though timeouts are already handled by the queue. This commit removes the unnecessary timeout logic from the uipc module. --- include/uipc.sh | 67 ++++++------------------------------------------- 1 file changed, 8 insertions(+), 59 deletions(-) diff --git a/include/uipc.sh b/include/uipc.sh index a2f2b75..ad9eb21 100644 --- a/include/uipc.sh +++ b/include/uipc.sh @@ -324,23 +324,6 @@ _uipc_endpoint_put() { return 0 } -_uipc_endpoint_get() { - local endpoint="$1" - local -i timeout="$2" - - local queue - local msg - - queue="$__uipc_root/$endpoint/queue" - - if ! msg=$(queue_get "$queue" "$timeout"); then - return 1 - fi - - echo "$msg" - return 0 -} - uipc_endpoint_send() { local source="$1" local destination="$2" @@ -362,53 +345,19 @@ uipc_endpoint_send() { uipc_endpoint_recv() { local endpoint="$1" - local -i timeout="$2" + local -i timeout="${2--1}" - local -i start + local queue + local msg - if (( $# < 2 )); then - timeout=-1 - fi + queue="$__uipc_root/$endpoint/queue" - if ! start=$(date +"%s"); then - return 2 + if ! msg=$(queue_get "$queue" "$timeout"); then + return 1 fi - while true; do - local msg - local -i elapsed - local -i remaining - - remaining="$timeout" - - if (( timeout > 0 )); then - local now - - if ! now=$(date +"%s"); then - return 2 - fi - - elapsed=$((now - start)) - remaining=$((timeout - elapsed)) - - # Remaining must not be negative because _uipc_endpoint_get() takes - # that to mean "block (possibly forever) until a message arrives" - if (( remaining < 0 )); then - remaining=0 - fi - fi - - if msg=$(_uipc_endpoint_get "$endpoint" "$remaining"); then - echo "$msg" - return 0 - fi - - if (( remaining == 0 )); then - break - fi - done - - return 1 + echo "$msg" + return 0 } _uipc_endpoint_topic_create() { -- 2.47.3