]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/network/serv_network.c
merge hickups. TBC.
[citadel.git] / citadel / modules / network / serv_network.c
index eae59f394c1d1a99566e90d31c2b55e7e16fa33b..4518740bf1ac9d00754940659cfbe3070abb6f5b 100644 (file)
@@ -2,9 +2,9 @@
  * This module handles shared rooms, inter-Citadel mail, and outbound
  * mailing list processing.
  *
- * Copyright (c) 2000-2010 by the citadel.org team
+ * Copyright (c) 2000-2011 by the citadel.org team
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  This program is open source software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 3 of the License, or
  *  (at your option) any later version.
@@ -92,9 +92,6 @@
 
 
 
-/* Nonzero while we are doing network processing */
-static int doing_queue = 0;
-
 /*
  * When we do network processing, it's accomplished in two passes; one to
  * gather a list of rooms and one to actually do them.  It's ok that rplist
@@ -1989,7 +1986,7 @@ void receive_spool(int *sock, char *remote_nodename) {
                 * If shutting down we can exit here and unlink the temp file.
                 * this shouldn't loose us any messages.
                 */
-               if (CtdlThreadCheckStop())
+               if (server_shutting_down)
                {
                        fclose(fp);
                        unlink(tempfilename);
@@ -2031,7 +2028,7 @@ void receive_spool(int *sock, char *remote_nodename) {
        fclose(fp);
 
        /* Last chance for shutdown exit */
-       if (CtdlThreadCheckStop())
+       if (server_shutting_down)
        {
                unlink(tempfilename);
                return;
@@ -2102,7 +2099,7 @@ void transmit_spool(int *sock, char *remote_nodename)
                bytes_to_write = plen;
                while (bytes_to_write > 0L) {
                        /* Exit if shutting down */
-                       if (CtdlThreadCheckStop())
+                       if (server_shutting_down)
                        {
                                close(fd);
                                return;
@@ -2135,7 +2132,7 @@ ABORTUPL:
        close(fd);
 
        /* Last chance for shutdown exit */
-       if(CtdlThreadCheckStop())
+       if(server_shutting_down)
                return;
                
        if (sock_puts(sock, "UCLS 1") < 0) return;
@@ -2208,9 +2205,9 @@ void network_poll_node(char *node, char *secret, char *host, char *port) {
                }
        
                /* At this point we are authenticated. */
-               if (!CtdlThreadCheckStop())
+               if (!server_shutting_down)
                        receive_spool(&sock, node);
-               if (!CtdlThreadCheckStop())
+               if (!server_shutting_down)
                        transmit_spool(&sock, node);
        }
 
@@ -2247,7 +2244,7 @@ void network_poll_other_citadel_nodes(int full_poll) {
 
        /* Use the string tokenizer to grab one line at a time */
        for (i=0; i<num_tokens(working_ignetcfg, '\n'); ++i) {
-               if(CtdlThreadCheckStop())
+               if(server_shutting_down)
                        return;
                extract_token(linebuf, working_ignetcfg, i, '\n', sizeof linebuf);
                extract_token(node, linebuf, 0, '|', sizeof node);
@@ -2311,6 +2308,7 @@ void create_spool_dirs(void) {
  * Run through the rooms doing various types of network stuff.
  */
 void network_do_queue(void) {
+       static int doing_queue = 0;
        static time_t last_run = 0L;
        struct RoomProcList *ptr;
        int full_processing = 1;
@@ -2356,14 +2354,14 @@ void network_do_queue(void) {
        /* 
         * Go ahead and run the queue
         */
-       if (full_processing && !CtdlThreadCheckStop()) {
+       if (full_processing && !server_shutting_down) {
                syslog(LOG_DEBUG, "network: loading outbound queue\n");
                CtdlForEachRoom(network_queue_room, NULL);
        }
 
        if (rplist != NULL) {
                syslog(LOG_DEBUG, "network: running outbound queue\n");
-               while (rplist != NULL && !CtdlThreadCheckStop()) {
+               while (rplist != NULL && !server_shutting_down) {
                        char spoolroomname[ROOMNAMELEN];
                        safestrncpy(spoolroomname, rplist->name, sizeof spoolroomname);
                        begin_critical_section(S_RPLIST);
@@ -2388,7 +2386,7 @@ void network_do_queue(void) {
        }
 
        /* If there is anything in the inbound queue, process it */
-       if (!CtdlThreadCheckStop()) {
+       if (!server_shutting_down) {
                network_do_spoolin();
        }
 
@@ -2476,24 +2474,6 @@ int network_room_handler (struct ctdlroom *room)
        return 0;
 }
 
-void *ignet_thread(void *arg) {
-       struct CitContext ignet_thread_CC;
-
-       syslog(LOG_DEBUG, "ignet_thread() initializing\n");
-       CtdlFillSystemContext(&ignet_thread_CC, "IGnet Queue");
-       citthread_setspecific(MyConKey, (void *)&ignet_thread_CC);
-
-       while (!CtdlThreadCheckStop()) {
-               network_do_queue();
-               CtdlThreadSleep(60);
-       }
-
-       CtdlClearSystemContext();
-       return(NULL);
-}
-
-
-
 
 /*
  * Module entry point
@@ -2509,7 +2489,7 @@ CTDL_MODULE_INIT(network)
                CtdlRegisterProtoHook(cmd_nsyn, "NSYN", "Synchronize room to node");
                CtdlRegisterRoomHook(network_room_handler);
                CtdlRegisterCleanupHook(destroy_network_queue_room);
-               CtdlThreadCreate("SMTP Send", CTDLTHREAD_BIGSTACK, ignet_thread, NULL);
+               CtdlRegisterSessionHook(network_do_queue, EVT_TIMER);
        }
        return "network";
 }