From 555f79c1d4e8279370f365bcb9bc4a5e136e0e9e Mon Sep 17 00:00:00 2001 From: Pavel Charvat Date: Sun, 11 Feb 2018 17:32:48 +0100 Subject: [PATCH] Main recio: Avoid calling of read_handler() with zero available bytes. 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 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ucw/main-rec.c b/ucw/main-rec.c index 7279d99d..f13758e3 100644 --- a/ucw/main-rec.c +++ b/ucw/main-rec.c @@ -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 -- 2.39.2