2 * UCW Library -- Main Loop: Testing
4 * (c) 2004--2011 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
11 #include "ucw/mainloop.h"
19 static struct main_process mp;
20 static struct main_block_io fin, fout;
21 static struct main_hook hook;
22 static struct main_timer tm;
23 static struct main_signal sg;
24 static int sig_counter;
28 static void dread(struct main_block_io *bio)
30 if (bio->rpos < bio->rlen)
32 msg(L_INFO, "Read EOF");
37 msg(L_INFO, "Read done");
38 block_io_read(bio, rb, sizeof(rb));
42 static void derror(struct main_block_io *bio, int cause)
44 msg(L_INFO, "Error: %m !!! (cause %d)", cause);
48 static void dwrite(struct main_block_io *bio UNUSED)
50 msg(L_INFO, "Write done");
53 static int dhook(struct main_hook *ho UNUSED)
55 msg(L_INFO, "Hook called");
61 static void dtimer(struct main_timer *tm)
63 msg(L_INFO, "Timer tick");
64 timer_add_rel(tm, 11000);
65 timer_add_rel(tm, 10000);
68 static void dentry(void)
71 msg(L_INFO, "*** SUBPROCESS START ***");
73 msg(L_INFO, "*** SUBPROCESS FINISH ***");
77 static void dexit(struct main_process *pr)
79 msg(L_INFO, "Subprocess %d exited with status %x", pr->pid, pr->status);
82 static void dsignal(struct main_signal *sg UNUSED)
84 msg(L_INFO, "SIGINT received (send 3 times to really quit, or use Ctrl-\\)");
94 fin.read_done = dread;
95 fin.error_handler = derror;
96 block_io_add(&fin, 0);
97 block_io_read(&fin, rb, sizeof(rb));
99 fout.write_done = dwrite;
100 fout.error_handler = derror;
101 block_io_add(&fout, 1);
102 block_io_write(&fout, "Hello, world!\n", 14);
104 hook.handler = dhook;
108 timer_add_rel(&tm, 1000);
111 sg.handler = dsignal;
115 if (!process_fork(&mp))
121 msg(L_INFO, "Finished.");