gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r9516 - gnunet/src/util


From: gnunet
Subject: [GNUnet-SVN] r9516 - gnunet/src/util
Date: Sun, 15 Nov 2009 09:49:39 -0700

Author: grothoff
Date: 2009-11-15 09:49:39 -0700 (Sun, 15 Nov 2009)
New Revision: 9516

Modified:
   gnunet/src/util/client.c
   gnunet/src/util/connection.c
Log:
ignore shutdown support for client/connection and shutdown fix in connection

Modified: gnunet/src/util/client.c
===================================================================
--- gnunet/src/util/client.c    2009-11-15 15:48:38 UTC (rev 9515)
+++ gnunet/src/util/client.c    2009-11-15 16:49:39 UTC (rev 9516)
@@ -242,6 +242,11 @@
    */
   int in_receive;
 
+  /**
+   * Are we ignoring shutdown signals?
+   */
+  int ignore_shutdown;
+
 };
 
 
@@ -317,7 +322,23 @@
   return ret;
 }
 
+/**
+ * Configure this connection to ignore shutdown signals.
+ *
+ * @param h client handle
+ * @param do_ignore GNUNET_YES to ignore, GNUNET_NO to restore default
+ */
+void
+GNUNET_CLIENT_ignore_shutdown (struct GNUNET_CLIENT_Connection *h,
+                              int do_ignore)
+{
+  h->ignore_shutdown = do_ignore;
+  if (h->sock != NULL)
+    GNUNET_CONNECTION_ignore_shutdown (h->sock,
+                                      do_ignore);
+}
 
+
 /**
  * Destroy connection with the service.  This will automatically
  * cancel any pending "receive" request (however, the handler will
@@ -775,6 +796,9 @@
       th->sock->sock = do_connect (th->sock->sched,
                                    th->sock->service_name, th->sock->cfg);
       GNUNET_assert (NULL != th->sock->sock);
+      GNUNET_CONNECTION_ignore_shutdown (th->sock->sock,
+                                        th->sock->ignore_shutdown);
+
       delay = GNUNET_TIME_relative_min (delay, th->sock->back_off);
       th->sock->back_off 
        = GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply 
(th->sock->back_off, 2),
@@ -899,6 +923,10 @@
   msize = ntohs (tc->hdr->size);
   if (NULL == buf)
     {
+#if DEBUG_CLIENT
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                 _("Could not submit request, not expecting to receive a 
response.\n"));
+#endif
       tc->rn (tc->rn_cls, NULL);
       GNUNET_free (tc);
       return 0;

Modified: gnunet/src/util/connection.c
===================================================================
--- gnunet/src/util/connection.c        2009-11-15 15:48:38 UTC (rev 9515)
+++ gnunet/src/util/connection.c        2009-11-15 16:49:39 UTC (rev 9516)
@@ -270,6 +270,11 @@
   size_t max;
 
   /**
+   * Ignore GNUNET_SCHEDULER_REASON_SHUTDOWN for this socket.
+   */
+  int ignore_shutdown;
+
+  /**
    * Port to connect to.
    */
   uint16_t port;
@@ -490,8 +495,14 @@
       return;
     }
 #if DEBUG_CONNECTION
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroy actually runs (%p)!\n", sock);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
+             "Destroy actually runs (%p)!\n", sock);
 #endif
+  if (sock->dns_active != NULL)
+    {
+      GNUNET_RESOLVER_request_cancel (sock->dns_active);
+      sock->dns_active = NULL;
+    }
   GNUNET_assert (sock->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK);
   GNUNET_assert (sock->ccs == COCO_NONE);
   if (NULL != (notify = sock->nth.notify_ready))
@@ -911,9 +922,8 @@
       sock->dns_active = NULL;
     }
   GNUNET_assert (sock->sched != NULL);
-  GNUNET_SCHEDULER_add_after (sock->sched,
-                              GNUNET_SCHEDULER_NO_TASK,
-                              &destroy_continuation, sock);
+  GNUNET_SCHEDULER_add_now (sock->sched,
+                           &destroy_continuation, sock);
 }
 
 
@@ -962,6 +972,21 @@
   GNUNET_CONNECTION_Receiver receiver;
 
   sh->read_task = GNUNET_SCHEDULER_NO_TASK;
+  if ( (GNUNET_YES == sh->ignore_shutdown) &&
+       (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))) 
+    {
+      /* ignore shutdown request, go again immediately */
+#if DEBUG_CONNECTION
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                 "Ignoring shutdown signal per configuration\n");
+#endif
+      sh->read_task = GNUNET_SCHEDULER_add_read_net (tc->sched,
+                                                    
GNUNET_TIME_absolute_get_remaining
+                                                    (sh->receive_timeout),
+                                                    sh->sock,
+                                                    &receive_ready, sh);
+      return;
+    }
   now = GNUNET_TIME_absolute_get ();
   if ((now.value > sh->receive_timeout.value) ||
       (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) ||
@@ -1109,6 +1134,20 @@
 
 
 /**
+ * Configure this connection to ignore shutdown signals.
+ *
+ * @param sock socket handle
+ * @param do_ignore GNUNET_YES to ignore, GNUNET_NO to restore default
+ */
+void
+GNUNET_CONNECTION_ignore_shutdown (struct GNUNET_CONNECTION_Handle *sock,
+                                  int do_ignore)
+{
+  sock->ignore_shutdown = do_ignore;
+}
+
+
+/**
  * Cancel receive job on the given socket.  Note that the
  * receiver callback must not have been called yet in order
  * for the cancellation to be valid.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]