patch 8.1.2047: cannot check the current state

Problem:    Cannot check the current state.
Solution:   Add the state() function.
diff --git a/src/channel.c b/src/channel.c
index 0dab3be..f40d16a 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -3483,6 +3483,7 @@
  * Read from RAW or NL "channel"/"part".  Blocks until there is something to
  * read or the timeout expires.
  * When "raw" is TRUE don't block waiting on a NL.
+ * Does not trigger timers or handle messages.
  * Returns what was read in allocated memory.
  * Returns NULL in case of error or timeout.
  */
@@ -3569,6 +3570,17 @@
     return msg;
 }
 
+static int channel_blocking_wait = 0;
+
+/*
+ * Return TRUE if in a blocking wait that might trigger callbacks.
+ */
+    int
+channel_in_blocking_wait(void)
+{
+    return channel_blocking_wait > 0;
+}
+
 /*
  * Read one JSON message with ID "id" from "channel"/"part" and store the
  * result in "rettv".
@@ -3592,6 +3604,7 @@
     int		retval = FAIL;
 
     ch_log(channel, "Blocking read JSON for id %d", id);
+    ++channel_blocking_wait;
 
     if (id >= 0)
 	channel_add_block_id(chanpart, id);
@@ -3661,6 +3674,7 @@
     }
     if (id >= 0)
 	channel_remove_block_id(chanpart, id);
+    --channel_blocking_wait;
 
     return retval;
 }