wait for bots to be disconnected on shutdown
authorpk910 <philipp@zoelle1.de>
Mon, 24 Sep 2012 14:53:48 +0000 (16:53 +0200)
committerpk910 <philipp@zoelle1.de>
Mon, 24 Sep 2012 15:01:02 +0000 (17:01 +0200)
src/ClientSocket.c
src/main.c
src/main.h

index 7160014d36c18b089720ddf1e05f74743f4f9724..eb11d88fc131558ff1bb698f883c37bd91144188 100644 (file)
@@ -14,7 +14,7 @@
  * You should have received a copy of the GNU General Public License 
  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
  */
-
+#include "main.h"
 #include "ClientSocket.h"
 #include "IRCParser.h"
 #include "UserNode.h"
@@ -222,6 +222,8 @@ static IOHANDLER_CALLBACK(socket_callback) {
     #ifdef HAVE_THREADS
     unsigned int tid;
     #endif
+    if(process_state.running == 0)
+        return; //just ignore the event (shutdown sequence)
     switch(event->type) {
     case IOEVENT_CONNECTED:
         client->flags |= SOCKET_FLAG_CONNECTED;
index d26219077b1fd3442ab6035c4820ef1b78c74e8c..d17647d72f227ee3c5a4d742ca2e739d0e1b06f1 100644 (file)
 #include "IOHandler.h"
 #include "statistics.h"
 
-static struct {
-    time_t start_time;
-    int running : 1;
-    int restart : 1;
-    int run_as_daemon : 1;
-    int daemonized : 1;
-    int loglevel : 8;
-    int loaded_config : 1;
-    int running_threads : 8;
-    
-    int argc;
-    char **argv;
-    
-    char config[MAXLEN];
-    char pidfile[MAXLEN];
-} process_state;
+struct ProcessState process_state;
 
 static FILE *log_fptr = NULL;
 
@@ -199,7 +184,22 @@ void initialize_subsystems() {
 
 void shutdown_subsystems() {
     free_sockets(1);
-    usleep(10000); //wait for disconnect (10ms)
+    //wait 50ms (run iohandler)
+    {
+        struct timeval timeout, ctime1, ctime2;
+        gettimeofday(&ctime1, NULL);
+        ctime1.tv_usec += 50000;
+        if(ctime1.tv_usec > 1000000) {
+            ctime1.tv_usec -= 1000000;
+            ctime1.tv_sec++;
+        }
+        do {
+            timeout.tv_sec = 0;
+            timeout.tv_usec = 10000;
+            iohandler_poll_timeout(timeout);
+            gettimeofday(&ctime2, NULL);
+        } while(timeval_is_bigger(ctime1, ctime2));
+    }
     stop_modules();
     free_sockets(0);
     qserver_free();
index f429b67da41b3b02d7676c19be16ecaa175df9d5..85e4fd8e48af5a8c07a4826bce37eb4aed2d6fe9 100644 (file)
 #define _main_h
 #include "overall.h"
 
+struct ProcessState {
+    time_t start_time;
+    int running : 1;
+    int restart : 1;
+    int run_as_daemon : 1;
+    int daemonized : 1;
+    int loglevel : 8;
+    int loaded_config : 1;
+    int running_threads : 8;
+    
+    int argc;
+    char **argv;
+    
+    char config[MAXLEN];
+    char pidfile[MAXLEN];
+};
+
 #ifndef DND_FUNCTIONS
 
+extern struct ProcessState process_state;
+
 #ifdef HAVE_THREADS
 extern pthread_mutex_t cache_sync;
 extern pthread_mutex_t whohandler_sync, whohandler_mass_sync;