]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
2003-04-17 Havoc Pennington <hp@redhat.com>
authorHavoc Pennington <hp@redhat.com>
Thu, 17 Apr 2003 20:25:33 +0000 (20:25 +0000)
committerHavoc Pennington <hp@redhat.com>
Thu, 17 Apr 2003 20:25:33 +0000 (20:25 +0000)
* dbus/dbus-mainloop.c (_dbus_loop_iterate): fix logic so that if
there was an OOM watch we skipped, we always return TRUE so we
iterate again to have a look at it again. Fixes test suite hang.
Code rearrangement also lets us lose some memset and only iterate
over callbacks once.

* bus/driver.c (bus_driver_handle_message): sense of test for
reply was backward

ChangeLog
bus/dispatch.c
bus/driver.c
dbus/dbus-mainloop.c
dbus/dbus-transport-unix.c

index 069734da8e1ee878d781a3d78775ab60f569525e..ad4e7e51513c55328a707fa88f344ff8520d1225 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2003-04-17  Havoc Pennington  <hp@redhat.com>
+
+       * dbus/dbus-mainloop.c (_dbus_loop_iterate): fix logic so that if
+       there was an OOM watch we skipped, we always return TRUE so we
+       iterate again to have a look at it again. Fixes test suite hang.
+       Code rearrangement also lets us lose some memset and only iterate
+       over callbacks once.
+
+       * bus/driver.c (bus_driver_handle_message): sense of test for
+       reply was backward
+
 2003-04-16  Havoc Pennington  <hp@pobox.com>
 
        * doc/dbus-specification.sgml: make spec say serials are unsigned
index 595db33bea1d96c99405dbafaf36bb1d76bc8898..11fe515c62e0a2db1184367db3b7909af14b342e 100644 (file)
@@ -1922,7 +1922,7 @@ bus_dispatch_test (const DBusString *test_data_dir)
       _dbus_assert_not_reached ("initial connection setup failed");
     }
   
-  check1_try_iterations (context, "create_and_hello_sha1",
+  check1_try_iterations (context, "create_and_hello",
                          check_hello_connection);
   
   check2_try_iterations (context, foo, "nonexistent_service_activation",
@@ -1978,7 +1978,7 @@ bus_dispatch_sha1_test (const DBusString *test_data_dir)
       _dbus_assert_not_reached ("initial connection setup failed");
     }
   
-  check1_try_iterations (context, "create_and_hello",
+  check1_try_iterations (context, "create_and_hello_sha1",
                          check_hello_connection);
 
   kill_client_connection_unchecked (foo);
index 0d8b9442d176eb699bc835cd5d41eb00247bea52..c52020b59b4ed359be47067bf4163de2c4cb0586 100644 (file)
@@ -620,7 +620,7 @@ bus_driver_handle_message (DBusConnection *connection,
       return FALSE;
     }
 
-  if (dbus_message_get_reply_serial (message) != 0)
+  if (dbus_message_get_reply_serial (message) == 0)
     {
       _dbus_verbose ("Client sent a reply to the bus driver, ignoring it\n");
       return TRUE;
index 3c810f22c13115c65e4618feb0d21d6b255e1a67..95669ff45736bb15cc91da63f63993ea9d000656 100644 (file)
@@ -489,13 +489,13 @@ dbus_bool_t
 _dbus_loop_iterate (DBusLoop     *loop,
                     dbus_bool_t   block)
 {  
-#define N_STATIC_DESCRIPTORS 64
+#define N_STACK_DESCRIPTORS 64
   dbus_bool_t retval;
   DBusPollFD *fds;
-  DBusPollFD static_fds[N_STATIC_DESCRIPTORS];
+  DBusPollFD stack_fds[N_STACK_DESCRIPTORS];
   int n_fds;
   WatchCallback **watches_for_fds;
-  WatchCallback *static_watches_for_fds[N_STATIC_DESCRIPTORS];
+  WatchCallback *stack_watches_for_fds[N_STACK_DESCRIPTORS];
   int i;
   DBusList *link;
   int n_ready;
@@ -504,8 +504,8 @@ _dbus_loop_iterate (DBusLoop     *loop,
   dbus_bool_t oom_watch_pending;
   int orig_depth;
   
-  retval = FALSE;
-      
+  retval = FALSE;      
+
   fds = NULL;
   watches_for_fds = NULL;
   n_fds = 0;
@@ -520,104 +520,92 @@ _dbus_loop_iterate (DBusLoop     *loop,
   if (loop->callbacks == NULL)
     goto next_iteration;
 
-  /* count enabled watches */
-  n_fds = 0;
-  link = _dbus_list_get_first_link (&loop->callbacks);
-  while (link != NULL)
+  if (loop->watch_count > N_STACK_DESCRIPTORS)
     {
-      DBusList *next = _dbus_list_get_next_link (&loop->callbacks, link);
-      Callback *cb = link->data;
-      if (cb->type == CALLBACK_WATCH)
+      fds = dbus_new0 (DBusPollFD, loop->watch_count);
+      
+      while (fds == NULL)
         {
-          WatchCallback *wcb = WATCH_CALLBACK (cb);
-
-          if (!wcb->last_iteration_oom &&
-              dbus_watch_get_enabled (wcb->watch))
-            ++n_fds;
+          _dbus_wait_for_memory ();
+          fds = dbus_new0 (DBusPollFD, loop->watch_count);
         }
       
-      link = next;
+      watches_for_fds = dbus_new (WatchCallback*, loop->watch_count);
+      while (watches_for_fds == NULL)
+        {
+          _dbus_wait_for_memory ();
+          watches_for_fds = dbus_new (WatchCallback*, loop->watch_count);
+        }
+    }
+  else
+    {      
+      fds = stack_fds;
+      watches_for_fds = stack_watches_for_fds;
     }
 
   /* fill our array of fds and watches */
-  if (n_fds > 0)
+  n_fds = 0;
+  link = _dbus_list_get_first_link (&loop->callbacks);
+  while (link != NULL)
     {
-      if (n_fds > N_STATIC_DESCRIPTORS)
+      DBusList *next = _dbus_list_get_next_link (&loop->callbacks, link);
+      Callback *cb = link->data;
+      if (cb->type == CALLBACK_WATCH)
         {
-          fds = dbus_new0 (DBusPollFD, n_fds);
+          unsigned int flags;
+          WatchCallback *wcb = WATCH_CALLBACK (cb);
 
-          while (fds == NULL)
+          if (wcb->last_iteration_oom)
             {
-              _dbus_wait_for_memory ();
-              fds = dbus_new0 (DBusPollFD, n_fds);
+              /* we skip this one this time, but reenable it next time,
+               * and have a timeout on this iteration
+               */
+              wcb->last_iteration_oom = FALSE;
+              oom_watch_pending = TRUE;
+              
+              retval = TRUE; /* return TRUE here to keep the loop going,
+                              * since we don't know the watch is inactive
+                              */
+
+#if MAINLOOP_SPEW
+              _dbus_verbose ("  skipping watch on fd %d as it was out of memory last time\n",
+                             dbus_watch_get_fd (wcb->watch));
+#endif
             }
-          
-          watches_for_fds = dbus_new (WatchCallback*, n_fds);
-          while (watches_for_fds == NULL)
+          else if (dbus_watch_get_enabled (wcb->watch))
             {
-              _dbus_wait_for_memory ();
-              watches_for_fds = dbus_new (WatchCallback*, n_fds);
-            }
-        }
-      else
-        {
-          memset (static_fds, '\0', sizeof (static_fds[0]) * n_fds);
-          memset (static_watches_for_fds, '\0', sizeof (static_watches_for_fds[0]) * n_fds);
-          
-          fds = static_fds;
-          watches_for_fds = static_watches_for_fds;
-        }
-      
-      i = 0;
-      link = _dbus_list_get_first_link (&loop->callbacks);
-      while (link != NULL)
-        {
-          DBusList *next = _dbus_list_get_next_link (&loop->callbacks, link);
-          Callback *cb = link->data;
-          if (cb->type == CALLBACK_WATCH)
-            {
-              unsigned int flags;
-              WatchCallback *wcb = WATCH_CALLBACK (cb);
-
-              if (wcb->last_iteration_oom)
-                {
-                  /* we skip this one this time, but reenable it next time,
-                   * and have a timeout on this iteration
-                   */
-                  wcb->last_iteration_oom = FALSE;
-                  oom_watch_pending = TRUE;
-
-                  retval = TRUE; /* return TRUE here to keep the loop going,
-                                  * since we don't know the watch is inactive
-                                  */
-                  
-                  _dbus_verbose ("  skipping watch on fd %d as it was out of memory last time\n",
-                                 dbus_watch_get_fd (wcb->watch));
-                }
-              else if (dbus_watch_get_enabled (wcb->watch))
-                {
-                  watches_for_fds[i] = wcb;
+              watches_for_fds[n_fds] = wcb;
 
-                  callback_ref (cb);
+              callback_ref (cb);
                   
-                  flags = dbus_watch_get_flags (wcb->watch);
+              flags = dbus_watch_get_flags (wcb->watch);
                   
-                  fds[i].fd = dbus_watch_get_fd (wcb->watch);
-                  if (flags & DBUS_WATCH_READABLE)
-                    fds[i].events |= _DBUS_POLLIN;
-                  if (flags & DBUS_WATCH_WRITABLE)
-                    fds[i].events |= _DBUS_POLLOUT;
+              fds[n_fds].fd = dbus_watch_get_fd (wcb->watch);
+              fds[n_fds].revents = 0;
+              fds[n_fds].events = 0;
+              if (flags & DBUS_WATCH_READABLE)
+                fds[n_fds].events |= _DBUS_POLLIN;
+              if (flags & DBUS_WATCH_WRITABLE)
+                fds[n_fds].events |= _DBUS_POLLOUT;
 
-                  ++i;
-                }
+              n_fds += 1;
+
+#if MAINLOOP_SPEW
+              _dbus_verbose ("  polling watch on fd %d\n", fds[n_fds].fd);
+#endif
+            }
+          else
+            {
+#if MAINLOOP_SPEW
+              _dbus_verbose ("  skipping disabled watch on fd %d\n",
+                             dbus_watch_get_fd (wcb->watch));
+#endif
             }
-              
-          link = next;
         }
-
-      _dbus_assert (i == n_fds);
+              
+      link = next;
     }
-
+  
   timeout = -1;
   if (loop->timeout_count > 0)
     {
@@ -784,7 +772,7 @@ _dbus_loop_iterate (DBusLoop     *loop,
     }
       
  next_iteration:
-  if (fds && fds != static_fds)
+  if (fds && fds != stack_fds)
     dbus_free (fds);
   if (watches_for_fds)
     {
@@ -795,13 +783,13 @@ _dbus_loop_iterate (DBusLoop     *loop,
           ++i;
         }
       
-      if (watches_for_fds != static_watches_for_fds)
+      if (watches_for_fds != stack_watches_for_fds)
         dbus_free (watches_for_fds);
     }
   
   if (_dbus_loop_dispatch (loop))
     retval = TRUE;
-
+  
 #if MAINLOOP_SPEW
   _dbus_verbose ("Returning %d\n", retval);
 #endif
index 50d8630199c818c005a6bb94639f1423c9872a92..82b28e0d7dc9a4a00501f78e194941150283ba76 100644 (file)
@@ -725,14 +725,17 @@ unix_handle_watch (DBusTransport *transport,
   if (watch == unix_transport->read_watch &&
       (flags & DBUS_WATCH_READABLE))
     {
-#if 0
+#if 1
       _dbus_verbose ("handling read watch\n");
 #endif
       if (!do_authentication (transport, TRUE, FALSE))
         return FALSE;
       
       if (!do_reading (transport))
-        return FALSE;
+        {
+          _dbus_verbose ("no memory to read\n");
+          return FALSE;
+        }
     }
   else if (watch == unix_transport->write_watch &&
            (flags & DBUS_WATCH_WRITABLE))
@@ -745,7 +748,10 @@ unix_handle_watch (DBusTransport *transport,
         return FALSE;
       
       if (!do_writing (transport))
-        return FALSE;
+        {
+          _dbus_verbose ("no memory to write\n");
+          return FALSE;
+        }
     }
 #ifdef DBUS_ENABLE_VERBOSE_MODE
   else