]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/main-test.c
Added string functions for matching of prefixes and suffixes
[libucw.git] / ucw / main-test.c
index 1df357bb02b982def134f3c709b2b1fb2f742d2c..f349d4dfe0801cf8da1a4ac94a861a0a0401a2c8 100644 (file)
@@ -21,6 +21,7 @@ static struct main_block_io fin, fout;
 static struct main_hook hook;
 static struct main_timer tm;
 static struct main_signal sg;
 static struct main_hook hook;
 static struct main_timer tm;
 static struct main_signal sg;
+static int sig_counter;
 
 static byte rb[16];
 
 
 static byte rb[16];
 
@@ -29,18 +30,21 @@ static void dread(struct main_block_io *bio)
   if (bio->rpos < bio->rlen)
     {
       msg(L_INFO, "Read EOF");
   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_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);
     }
 }
 
 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);
 }
 
   block_io_del(bio);
 }
 
@@ -52,6 +56,8 @@ static void dwrite(struct main_block_io *bio UNUSED)
 static int dhook(struct main_hook *ho UNUSED)
 {
   msg(L_INFO, "Hook called");
 static int dhook(struct main_hook *ho UNUSED)
 {
   msg(L_INFO, "Hook called");
+  if (sig_counter >= 3)
+    return HOOK_SHUTDOWN;
   return 0;
 }
 
   return 0;
 }
 
@@ -65,6 +71,7 @@ static void dtimer(struct main_timer *tm)
 static void dentry(void)
 {
   log_fork();
 static void dentry(void)
 {
   log_fork();
+  main_teardown();
   msg(L_INFO, "*** SUBPROCESS START ***");
   sleep(2);
   msg(L_INFO, "*** SUBPROCESS FINISH ***");
   msg(L_INFO, "*** SUBPROCESS START ***");
   sleep(2);
   msg(L_INFO, "*** SUBPROCESS FINISH ***");
@@ -78,7 +85,8 @@ static void dexit(struct main_process *pr)
 
 static void dsignal(struct main_signal *sg UNUSED)
 {
 
 static void dsignal(struct main_signal *sg UNUSED)
 {
-  msg(L_INFO, "SIGINT received (use Ctrl-\\ to really quit)");
+  msg(L_INFO, "SIGINT received (send 3 times to really quit, or use Ctrl-\\)");
+  sig_counter++;
 }
 
 int
 }
 
 int
@@ -89,11 +97,13 @@ main(void)
 
   fin.read_done = dread;
   fin.error_handler = derror;
 
   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;
   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);
 
   block_io_add(&fout, 1);
   block_io_write(&fout, "Hello, world!\n", 14);
 
@@ -115,6 +125,16 @@ main(void)
 
   main_loop();
   msg(L_INFO, "Finished.");
 
   main_loop();
   msg(L_INFO, "Finished.");
+
+  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;
 }
 
 #endif
 }
 
 #endif