SILC FSM API changes.
[silc.git] / lib / silcutil / tests / test_silcfdstream.c
index dcdccdd471574ce34b94b05a8194835470ccb2d1..c0039b1ce5f73d72deef4b6035e42bc5751f06b4 100644 (file)
@@ -1,6 +1,6 @@
 /* SILC FD Stream tests */
 
-#include "silcincludes.h"
+#include "silc.h"
 
 SilcBool success = FALSE;
 SilcSchedule schedule;
@@ -32,7 +32,7 @@ SILC_FSM_STATE(st_end)
 {
   unlink("/tmp/test_silcfdstream");
   unlink("/tmp/test_silcfdstream_copy");
-  return SILC_FSM_FINISH;
+  SILC_FSM_FINISH;
 }
 
 SILC_FSM_STATE(st_readwrite)
@@ -58,13 +58,13 @@ SILC_FSM_STATE(st_readwrite)
   }
 
   SILC_LOG_DEBUG(("Creating FD stream (two fds)"));
-  stream = silc_fd_stream_create2(fd1, fd2, schedule);
+  stream = silc_fd_stream_create2(fd1, fd2);
   if (!stream) {
     SILC_LOG_DEBUG(("Error creating stream"));
     goto err;
   }
 
-  silc_stream_set_notifier(stream, stream_notifier2, fsm);
+  silc_stream_set_notifier(stream, schedule, stream_notifier2, fsm);
 
   /* Stream between the fiels */
   SILC_LOG_DEBUG(("Read/write 3 bytes at a time"));
@@ -83,7 +83,7 @@ SILC_FSM_STATE(st_readwrite)
       if (i == -1) {
         SILC_LOG_DEBUG(("Would block, write later"));
         silc_fsm_next(fsm, st_end);
-        return SILC_FSM_WAIT;
+        SILC_FSM_WAIT;
       }
 
       if (i == -2) {
@@ -99,7 +99,7 @@ SILC_FSM_STATE(st_readwrite)
   if (ret == -1) {
     SILC_LOG_DEBUG(("Would block, read later"));
     silc_fsm_next(fsm, st_end);
-    return SILC_FSM_WAIT;
+    SILC_FSM_WAIT;
   }
 
   if (ret == -2) {
@@ -115,38 +115,31 @@ SILC_FSM_STATE(st_readwrite)
     SILC_LOG_DEBUG(("Destroying stream"));
     silc_stream_destroy(stream);
   }
+
   silc_fsm_next(fsm, st_end);
-  return SILC_FSM_CONTINUE;
+  SILC_FSM_CONTINUE;
 
  err:
   silc_fsm_next(fsm, st_end);
-  return SILC_FSM_CONTINUE;
+  SILC_FSM_CONTINUE;
 }
 
 SILC_FSM_STATE(st_write)
 {
-  int ret, i, k, fd;
+  int ret, i, k;
   char *cp;
 
   /* Simple writing example */
   SILC_LOG_DEBUG(("Open file /tmp/test_silcfdstream for writing"));
-
-  unlink("/tmp/test_silcfdstream");
-  fd = silc_file_open("/tmp/test_silcfdstream", O_CREAT | O_RDWR);
-  if (fd < 0) {
-    SILC_LOG_DEBUG(("Error opening file"));
-    goto err;
-  }
-
   SILC_LOG_DEBUG(("Creating FD stream"));
-  stream = silc_fd_stream_create(fd, schedule);
+  unlink("/tmp/test_silcfdstream");
+  stream = silc_fd_stream_file("/tmp/test_silcfdstream", FALSE, TRUE);
   if (!stream) {
     SILC_LOG_DEBUG(("Error creating stream"));
     goto err;
   }
 
-  silc_stream_set_notifier(stream, stream_notifier, fsm);
+  silc_stream_set_notifier(stream, schedule, stream_notifier, fsm);
 
   memset(buf1, 0, sizeof(buf1));
   for (i = 0; i < sizeof(buf1); i++)
@@ -166,7 +159,7 @@ SILC_FSM_STATE(st_write)
     if (ret == -1) {
       SILC_LOG_DEBUG(("Would block, write later"));
       silc_fsm_next(fsm, st_readwrite);
-      return SILC_FSM_WAIT;
+      SILC_FSM_WAIT;
     }
 
     if (ret == -2) {
@@ -186,11 +179,11 @@ SILC_FSM_STATE(st_write)
 
   SILC_LOG_DEBUG(("Continue to next state"));
   silc_fsm_next(fsm, st_readwrite);
-  return SILC_FSM_CONTINUE;
+  SILC_FSM_CONTINUE;
 
  err:
   silc_fsm_next(fsm, st_end);
-  return SILC_FSM_CONTINUE;
+  SILC_FSM_CONTINUE;
 }
 
 static void fsm_dest(SilcFSM fsm, void *fsm_context, void *context)
@@ -206,7 +199,7 @@ int main(int argc, char **argv)
   if (argc > 1 && !strcmp(argv[1], "-d")) {
     silc_log_debug(TRUE);
     silc_log_debug_hexdump(TRUE);
-    silc_log_set_debug_string("fdstream*");
+    silc_log_set_debug_string("*fdstream*");
   }
 
   SILC_LOG_DEBUG(("Allocating scheduler"));