From 090e597d6290b4b411889817268b242df3c90c64 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 26 Feb 2011 23:50:16 +0100 Subject: [PATCH] Main: Add block_io_set_timeout() as promised in the docs --- ucw/main-block.c | 9 +++++++++ ucw/main-test.c | 11 +++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ucw/main-block.c b/ucw/main-block.c index 98c558e6..c3e173ce 100644 --- a/ucw/main-block.c +++ b/ucw/main-block.c @@ -132,3 +132,12 @@ block_io_write(struct main_block_io *bio, void *buf, uns len) } file_chg(&bio->file); } + +void +block_io_set_timeout(struct main_block_io *bio, timestamp_t expires_delta) +{ + if (!expires_delta) + timer_del(&bio->timer); + else + timer_add_rel(&bio->timer, expires_delta); +} diff --git a/ucw/main-test.c b/ucw/main-test.c index 2cf10f63..f349d4df 100644 --- a/ucw/main-test.c +++ b/ucw/main-test.c @@ -30,18 +30,21 @@ static void dread(struct main_block_io *bio) if (bio->rpos < bio->rlen) { msg(L_INFO, "Read EOF"); + bio->data = NULL; // Mark as deleted block_io_del(bio); } else { msg(L_INFO, "Read done"); block_io_read(bio, rb, sizeof(rb)); + block_io_set_timeout(&fin, 3000); } } static void derror(struct main_block_io *bio, int cause) { msg(L_INFO, "Error: %m !!! (cause %d)", cause); + bio->data = NULL; block_io_del(bio); } @@ -94,11 +97,13 @@ main(void) fin.read_done = dread; fin.error_handler = derror; + fin.data = ""; block_io_add(&fin, 0); block_io_read(&fin, rb, sizeof(rb)); fout.write_done = dwrite; fout.error_handler = derror; + fout.data = ""; block_io_add(&fout, 1); block_io_write(&fout, "Hello, world!\n", 14); @@ -121,8 +126,10 @@ main(void) main_loop(); msg(L_INFO, "Finished."); - block_io_del(&fin); - block_io_del(&fout); + if (fin.data) + block_io_del(&fin); + if (fout.data) + block_io_del(&fout); hook_del(&hook); signal_del(&sg); timer_del(&tm); -- 2.39.5