Merge commit 'origin/silc.1.1.branch'
[silc.git] / lib / silcserver / server.c
index 974e14d9572057cdf97b65ccd23d6a3420ec8499..27609a5a4dce3aa71733a086398047fabb455330 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2005 Pekka Riikonen
+  Copyright (C) 1997 - 2006 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -80,7 +80,7 @@ static SilcBool silc_server_packet_receive(SilcPacketEngine engine,
   /* Signal thread that packet has arrived */
   if (!thread->new_packet) {
     thread->new_packet = TRUE;
-    SILC_FSM_SEMA_POST(&thread->wait_event);
+    SILC_FSM_EVENT_SIGNAL(&thread->wait_event);
   }
 
   return TRUE;
@@ -190,7 +190,7 @@ static void silc_server_accept_connection(SilcNetStatus status,
   /* Signal server of new connection */
   if (!server->new_connection) {
     server->new_connection = TRUE;
-    SILC_FSM_SEMA_POST(&server->wait_event);
+    SILC_FSM_EVENT_SIGNAL(&server->wait_event);
   }
 }
 
@@ -216,11 +216,11 @@ SILC_FSM_STATE(silc_server_thread_st_start)
 
   /*** Run thread's machine */
   silc_fsm_init(&thread->fsm, thread, NULL, NULL, silc_fsm_get_schedule(fsm));
-  silc_fsm_sema_init(&thread->wait_event, &thread->fsm, 0);
+  silc_fsm_event_init(&thread->wait_event, &thread->fsm, 0);
   silc_fsm_start_sync(&thread->fsm, silc_server_thread_st_run);
 
   /* Signal server that we are up */
-  SILC_FSM_SEMA_POST(&thread->server->thread_up);
+  SILC_FSM_EVENT_SIGNAL(&thread->server->thread_up);
 
   /* Wait here for this thread to finish */
   return SILC_FSM_WAIT;
@@ -235,7 +235,7 @@ SILC_FSM_STATE(silc_server_thread_st_run)
   SILC_LOG_DEBUG(("Start"));
 
   /* Wait for events */
-  SILC_FSM_SEMA_WAIT(&thread->wait_event);
+  SILC_FSM_EVENT_WAIT(&thread->wait_event);
 
   /* Process events */
 
@@ -249,6 +249,7 @@ SILC_FSM_STATE(silc_server_thread_st_run)
     /* Each packet is processed in FSM thread */
     silc_list_start(thread->packet_queue);
     while ((packet = silc_list_get(thread->packet_queue)) != SILC_LIST_END) {
+      /* XXX shouldn't the fsm be &thread->fsm */
       t = silc_fsm_thread_alloc(fsm, thread, silc_server_thread_packet_dest,
                                NULL, FALSE);
       if (t) {
@@ -276,10 +277,10 @@ SILC_FSM_STATE(silc_server_thread_st_run)
     silc_list_start(thread->new_conns);
     while ((ac = silc_list_get(thread->new_conns)) != SILC_LIST_END) {
       ac->thread = thread;
-      ac->t = silc_fsm_thread_alloc(&thread->fsm, ac,
-                                   silc_server_accept_connection_dest,
-                                   NULL, FALSE);
-      silc_fsm_start(ac->t, silc_server_st_accept_connection);
+      silc_fsm_thread_init(&ac->t, &thread->fsm, ac,
+                          silc_server_accept_connection_dest,
+                          NULL, FALSE);
+      silc_fsm_start(&ac->t, silc_server_st_accept_connection);
     }
 
     /* Empty the list */
@@ -309,7 +310,7 @@ SILC_FSM_STATE(silc_server_st_run)
   SILC_LOG_DEBUG(("Start"));
 
   /* Wait for events */
-  SILC_FSM_SEMA_WAIT(&server->wait_event);
+  SILC_FSM_EVENT_WAIT(&server->wait_event);
 
   /* Process events */
 
@@ -405,7 +406,7 @@ SILC_FSM_STATE(silc_server_st_new_connection)
     /* Signal the thread for new connection */
     if (!thread->new_connection) {
       thread->new_connection = TRUE;
-      SILC_FSM_SEMA_POST(&thread->wait_event);
+      SILC_FSM_EVENT_SIGNAL(&thread->wait_event);
     }
     silc_mutex_unlock(server->lock);
   }
@@ -424,7 +425,7 @@ SILC_FSM_STATE(silc_server_st_wait_new_thread)
   SilcServer server = fsm_context;
 
   /* Wait here until new thread is up */
-  SILC_FSM_SEMA_WAIT(&server->thread_up);
+  SILC_FSM_EVENT_WAIT(&server->thread_up);
 
   /** Process new connections */
   silc_fsm_next(fsm, silc_server_st_new_connection);
@@ -591,8 +592,8 @@ SilcServer silc_server_alloc(void *app_context, SilcServerParams params,
   silc_fsm_init(&server->fsm, server, silc_server_destructor, NULL, schedule);
 
   /* Init semaphore signallers */
-  silc_fsm_sema_init(&server->wait_event, &server->fsm, 0);
-  silc_fsm_sema_init(&server->thread_up, &server->fsm, 0);
+  silc_fsm_event_init(&server->wait_event, &server->fsm, 0);
+  silc_fsm_event_init(&server->thread_up, &server->fsm, 0);
 
   /* Initialize lists */
   silc_list_init(server->new_conns, struct SilcServerAcceptStruct, next);
@@ -852,16 +853,16 @@ void silc_server_run(SilcServer server, SilcServerRunning running,
 
   /* Signal the application when we are running */
   server->run_callback = TRUE;
-  SILC_FSM_SEMA_POST(&server->wait_event);
+  SILC_FSM_EVENT_SIGNAL(&server->wait_event);
 
   /* Signal to connect to router */
   server->connect_router = TRUE;
-  SILC_FSM_SEMA_POST(&server->wait_event);
+  SILC_FSM_EVENT_SIGNAL(&server->wait_event);
 
   /* Start getting statistics from the network on normal server */
   if (server->server_type != SILC_ROUTER) {
     server->get_statistics = TRUE;
-    SILC_FSM_SEMA_POST(&server->wait_event);
+    SILC_FSM_EVENT_SIGNAL(&server->wait_event);
   }
 }
 
@@ -877,7 +878,7 @@ void silc_server_stop(SilcServer server, SilcServerStop stopped,
 
   /* Signal that server is going down */
   server->server_shutdown = TRUE;
-  SILC_FSM_SEMA_POST(&server->wait_event);
+  SILC_FSM_EVENT_SIGNAL(&server->wait_event);
 }
 
 /* Disconnects remote connection */