]> mj.ucw.cz Git - libucw.git/commitdiff
Main recio: Avoid calling of read_handler() with zero available bytes.
authorPavel Charvat <pchar@ucw.cz>
Sun, 11 Feb 2018 16:32:48 +0000 (17:32 +0100)
committerPavel Charvat <pchar@ucw.cz>
Sun, 11 Feb 2018 16:32:48 +0000 (17:32 +0100)
The problem was in the deferred hook. Also changed it's return value,
hooks like this should always return HOOK_IDLE and not slower HOOK_RETRY.

ucw/main-rec.c

index 7279d99d2a00edeb47dde42293fc994dc57e5a4e..f13758e3ecaa1a98af2665f60f8618846ef3724d 100644 (file)
@@ -77,11 +77,13 @@ static int
 rec_io_process_read_buf(struct main_rec_io *rio)
 {
   uint got;
+  ASSERT(rio->read_prev_avail < rio->read_avail);
   while (rio->read_running && (got = rio->read_handler(rio)))
     {
       DBG("RIO READ: Ate %u bytes", got);
       if (got == ~0U)
        return HOOK_IDLE;
+      ASSERT(got <= rio->read_avail);
       rio->read_rec_start += got;
       rio->read_avail -= got;
       rio->read_prev_avail = 0;
@@ -181,7 +183,10 @@ rec_io_deferred_start_read(struct main_hook *ho)
   rio->read_running = 1;
 
   rio->read_prev_avail = 0;
-  return rec_io_process_read_buf(rio);
+  if (rio->read_avail)
+    rec_io_process_read_buf(rio);
+
+  return HOOK_IDLE;
 }
 
 static void