ignore shutdown support for client/connection and shutdown fix in connection
authorChristian Grothoff <christian@grothoff.org>
Sun, 15 Nov 2009 16:49:39 +0000 (16:49 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sun, 15 Nov 2009 16:49:39 +0000 (16:49 +0000)
src/util/client.c
src/util/connection.c

index 4b84937bfafa64212b547c85b408dd3000b3cda9..6d1c6668759b2eccb2b2529fcc58f049ece5f198 100644 (file)
@@ -242,6 +242,11 @@ struct GNUNET_CLIENT_Connection
    */
   int in_receive;
 
+  /**
+   * Are we ignoring shutdown signals?
+   */
+  int ignore_shutdown;
+
 };
 
 
@@ -317,6 +322,22 @@ GNUNET_CLIENT_connect (struct GNUNET_SCHEDULER_Handle *sched,
   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
@@ -775,6 +796,9 @@ client_notify (void *cls, size_t size, void *buf)
       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 @@ transmit_for_response (void *cls, size_t size, void *buf)
   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;
index c12ea2751e35d7fd0fb11e63cf730fb441371ef6..468fb750c7372de6de71fab46e5cf8c0e545f216 100644 (file)
@@ -269,6 +269,11 @@ struct GNUNET_CONNECTION_Handle
    */
   size_t max;
 
+  /**
+   * Ignore GNUNET_SCHEDULER_REASON_SHUTDOWN for this socket.
+   */
+  int ignore_shutdown;
+
   /**
    * Port to connect to.
    */
@@ -490,8 +495,14 @@ destroy_continuation (void *cls,
       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 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock)
       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 @@ receive_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   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)) ||
@@ -1108,6 +1133,20 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *sock,
 }
 
 
+/**
+ * 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