Fixed timeout-related crashes.
authorshort <>
Fri, 21 May 2004 06:48:22 +0000 (06:48 +0000)
committershort <>
Fri, 21 May 2004 06:48:22 +0000 (06:48 +0000)
+Debug messages of timeout functionality for -v|--verbose.

src/network.c

index e3740a6..ad650b8 100644 (file)
@@ -38,6 +38,7 @@
 
 #include "network.h"
 #include "packet.h"
+#include "main.h"      /* for optarg_verbose */
 
 
 /* Config: */
@@ -131,6 +132,8 @@ static void client_timeout_remove(struct client *client)
        if (client->timeout_id) {
 gboolean errgboolean;
 
+               if (optarg_verbose)
+                       g_message(_("Client fd %d removed timeout id %d"),client->gpollfd.fd,client->timeout_id);
                errgboolean=g_source_remove(client->timeout_id);
                g_assert(errgboolean==TRUE);
                client->timeout_id=0;
@@ -149,6 +152,8 @@ static void client_touch(struct client *client)
                        (client==probe ? PROBE_TIMEOUT_SEC*1000 : CLIENT_TIMEOUT_SEC*1000),     /* interval; msec */
                        (GSourceFunc)client_touch_timeout,      /* function */
                        client);        /* data */
+       if (optarg_verbose)
+               g_message(_("Client fd %d new timeout id %d"),client->gpollfd.fd,client->timeout_id);
        g_assert(client->timeout_id!=0);
 }
 
@@ -159,13 +164,27 @@ static gboolean client_touch_timeout(struct client *client)
        g_return_val_if_fail(client!=NULL,FALSE);       /* FALSE=>should be removed */
        g_return_val_if_fail(client!=master,FALSE);     /* FALSE=>should be removed */
 
+       if (optarg_verbose)
+               g_message(_("Client fd %d timeout id %d occured/entered"),client->gpollfd.fd,client->timeout_id);
+
+       /* Do not destroy the timeout in client_destroy().
+        * It would crash GLib - we remove it be returning FALSE from here.
+        */
+       g_assert(client->timeout_id!=0);
+       client->timeout_id=0;
+
        if (client==probe) {
                network_stop();
+               /* Never destroy 'client' now - it has been destroyed by network_stop()! */
                if (network_notify_hostip)
                        (*network_notify_hostip)(0);
                }
+       else {
+               client_destroy(client);
+               }
 
-       client_destroy(client);
+       if (optarg_verbose)
+               g_message(_("Client timeout occurance finish"));
 
        return FALSE;   /* GSource should be removed */
 }
@@ -451,6 +470,9 @@ int sock;
        sock_client_list=g_list_prepend(sock_client_list,client);
        g_source_add_poll(sock_gsource,&client->gpollfd);
 
+       if (optarg_verbose)
+               g_message(_("Client fd %d created"),client->gpollfd.fd);
+
        return client;
 }
 
@@ -461,6 +483,9 @@ static void client_destroy(struct client *client)
        if (!sock_gsource_new())
                return;
 
+       if (optarg_verbose)
+               g_message(_("Client fd %d timeout id %d destroy enter"),client->gpollfd.fd,client->timeout_id);
+
        if (client==master) {
                master=NULL;
                g_assert(client->timeout_id==0);
@@ -474,6 +499,10 @@ static void client_destroy(struct client *client)
        g_source_remove_poll(sock_gsource,&client->gpollfd);
        sock_client_list=g_list_remove(sock_client_list,client);
        close(client->gpollfd.fd);      /* errors ignored */
+
+       if (optarg_verbose)
+               g_message(_("Client fd %d timeout id %d destroy finish"),client->gpollfd.fd,client->timeout_id);
+
        g_free(client);
 }