X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Fmain-test.c;h=8e9f376c78bcdccb70c39c327704df6fbb07bdec;hb=f17e4350dcf0c033891e52b30b0c32a4a4fed5e0;hp=41b6b5c6f3d36ed63f974a9f32d3259b537594de;hpb=60418b4db60801d7c3fc995bf71f53ff5d898484;p=libucw.git diff --git a/ucw/main-test.c b/ucw/main-test.c index 41b6b5c6..8e9f376c 100644 --- a/ucw/main-test.c +++ b/ucw/main-test.c @@ -7,8 +7,8 @@ * of the GNU Lesser General Public License. */ -#include "ucw/lib.h" -#include "ucw/mainloop.h" +#include +#include #include #include @@ -30,18 +30,32 @@ 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); + switch (cause) + { + case BIO_ERR_READ: + case BIO_ERR_WRITE: + msg(L_INFO, "derror: %s error: %m", (cause == BIO_ERR_READ ? "read" : "write")); + break; + case BIO_ERR_TIMEOUT: + msg(L_INFO, "derror: Timeout"); + break; + default: + ASSERT(0); + } + bio->data = NULL; block_io_del(bio); } @@ -68,6 +82,7 @@ static void dtimer(struct main_timer *tm) static void dentry(void) { log_fork(); + main_teardown(); msg(L_INFO, "*** SUBPROCESS START ***"); sleep(2); msg(L_INFO, "*** SUBPROCESS FINISH ***"); @@ -93,11 +108,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); @@ -120,10 +137,13 @@ 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); main_cleanup(); return 0; }