]> git.corax.cc Git - toolbox/commitdiff
include/uipc: Remove timeout logic from uipc_endpoint_recv()
authorMatthias Kruk <m@m10k.eu>
Mon, 26 Dec 2022 05:24:15 +0000 (14:24 +0900)
committerMatthias Kruk <m@m10k.eu>
Mon, 26 Dec 2022 05:24:15 +0000 (14:24 +0900)
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

index a2f2b75b5bcb8e5ecf892b05461c30f6fc96a968..ad9eb214d3ef504160205d42de6c3ace80f0903d 100644 (file)
@@ -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() {