From: Martin Mares Date: Sat, 26 Feb 2011 22:50:16 +0000 (+0100) Subject: Main: Add block_io_set_timeout() as promised in the docs X-Git-Tag: v5.0~129^2~7 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=090e597d6290b4b411889817268b242df3c90c64;p=libucw.git Main: Add block_io_set_timeout() as promised in the docs --- 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);