read complete line immediately if partial line is received

This commit is contained in:
2024-09-30 14:55:20 +02:00
parent df9b79f931
commit 59dabc3565

View File

@@ -459,32 +459,36 @@ function main() {
done
read -r -t 1 -u $STDIN buf
rc=$?
if (( rc > 128 )); then
if (( rc == 0 )); then
# received complete line from stdin
line=$buf
elif (( rc > 128 )); then
# read timed out, check for partial data
if [ -n "$buf" ]; then
echo "< $buf (partial line)" >&$DEBUGLOG
line=$buf
# read the rest of the line
read -r -u $STDIN buf || exit 255
line+=$buf
echo "< $buf (partial line: '$line')" >&$DEBUGLOG
fi
continue
elif (( rc == 0 )); then
line+=$buf
echo "< $line" >&$DEBUGLOG
else
exit 255
fi
echo "< $line" >&$DEBUGLOG
if [ -z $cmd ]; then
cmd=$line
args=()
elif [ -z $line ]; then
cmd=""
args=()
line=""
echo "empty argument" >&$DEBUGLOG
snmp_echo NONE
continue
else
args+=("$line")
fi
line=""
case "${cmd,,}" in
ping)
cmd=""