# set $line variable for further processing transport_plus_ipc_read_line() { local postpone_ipc=0 while true do local n_msgs=$(wc -l "${IPC_QUEUE_FILE}" 2> /dev/null | cut -d ' ' -f 1) # set $line variable from IPC message if ! (( ${postpone_ipc} )) && (( ${n_msgs} )) && [[ -w "${IPC_QUEUE_FILE}" ]] then read -r line < "${IPC_QUEUE_FILE}" if [[ "${line}" =~ ^([0-9]{10})\ (#[^\ ]*)\ ([^\ ].*)$ ]] then local delivery_time="${BASH_REMATCH[1]}" local target_channel="${BASH_REMATCH[2]}" local message="${BASH_REMATCH[3]}" local pending_line="${IPC_INJECT_PREFIX} ${target_channel} :${message}" local should_postpone=$( (( ${delivery_time} > $(date +%s) )) && echo 1 || echo 0) line=$( ! (( ${should_postpone} )) && echo "${pending_line}" || echo '') # echo "[IPC]: delivery_time=${BASH_REMATCH[1]}" # echo "[IPC]: target_channel=${BASH_REMATCH[2]}" # echo "[IPC]: message=${BASH_REMATCH[3]}" # echo "[IPC]: pending_line=${pending_line}" [[ -n "${line}" ]] && log_info "[IPC]: relaying to channel: ${target_channel} msg: ${message}" # || log_info "[IPC]: postponing" else line='ERROR: invalid IPC message: ${line}' fi [[ -z "${line}" ]] && postpone_ipc=1 && continue if (( ${n_msgs} < 2 )) then echo -n > "${IPC_QUEUE_FILE}" else tail -n +2 "${IPC_QUEUE_FILE}" | sponge "${IPC_QUEUE_FILE}" fi break # set $line variable from network message else read -t 5 -ru 3 line the_return_code="${?}" (( the_return_code == 0 )) && break (( the_return_code > 128 )) && continue [[ "${the_return_code}" -ne 0 ]] && return fi done time_get_current 'transport_lastvalidtime' line=${line//$'\r'/} }