summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xircmsg.sh17
1 files changed, 16 insertions, 1 deletions
diff --git a/ircmsg.sh b/ircmsg.sh
index 754d736..a504466 100755
--- a/ircmsg.sh
+++ b/ircmsg.sh
@@ -24,12 +24,22 @@ portfd=''
# matching "PING". Retrieves value of that line (without the PING prefix), and
# returns so the corresponding PONG can be sent.
#
+# Note: This function will timeout when reading from the server 100 times
+#
function get_ping {
local portfd=${1}
+ local emptymax=50
+ local emptycount=0
# get ping
- while [[ ${ping:0:4} != 'PING' ]]; do
+ while [[ ${emptycount} -lt ${emptymax} ]]; do
read ping <&${portfd}
+
+ # If first four match PING, break and process
+ [[ ${ping:0:4} == 'PING' ]] && break
+
+ # If response is empty, increment empty counter
+ [[ ${ping} == '' ]] && emptycount=$(($emptycount + 1))
done
ping=${ping:5}
@@ -87,6 +97,11 @@ function main {
# Respond to the server with its ping value (ping pong)
ping=$(get_ping ${portfd})
+ if [[ ${ping} == '' ]]; then
+ echo "ERROR: No PING response received. Cannot continue."
+ exit 1
+ fi
+
echo "PONG ${ping}" >&${portfd}
# Send message to specified channel

Generated by cgit