dbus/dbus dbus-transport-unix.c,1.40,1.41

Colin Walters walters at freedesktop.org
Thu Oct 21 19:07:31 PDT 2004


Update of /cvs/dbus/dbus/dbus
In directory gabe:/tmp/cvs-serv16717/dbus

Modified Files:
	dbus-transport-unix.c 
Log Message:
2004-10-21  Colin Walters  <walters at verbum.org>

	* dbus/dbus-transport-unix.c (do_authentication): Return
	authentication status to callers.
	(unix_handle_watch): If we completed authentication this round,
	don't do another read.  Instead wait until the next iteration,
	after we've read any pending data in the auth buffer.
	(unix_do_iteration): Ditto.
	(unix_handle_watch): Updated for new do_authentication prototype.


Index: dbus-transport-unix.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-transport-unix.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- dbus-transport-unix.c	10 Aug 2004 03:07:00 -0000	1.40
+++ dbus-transport-unix.c	22 Oct 2004 02:07:29 -0000	1.41
@@ -321,14 +321,17 @@
 static dbus_bool_t
 do_authentication (DBusTransport *transport,
                    dbus_bool_t    do_reading,
-                   dbus_bool_t    do_writing)
+                   dbus_bool_t    do_writing,
+		   dbus_bool_t   *auth_completed)
 {
   dbus_bool_t oom;
+  dbus_bool_t orig_auth_state;
   
   _dbus_transport_ref (transport);
 
   oom = FALSE;
   
+  orig_auth_state = _dbus_transport_get_is_authenticated (transport);
   while (!_dbus_transport_get_is_authenticated (transport) &&
          _dbus_transport_get_is_connected (transport))
     {      
@@ -379,6 +382,9 @@
           break;
         }
     }
+
+  if (auth_completed)
+    *auth_completed = (orig_auth_state != _dbus_transport_get_is_authenticated (transport));
   
  out:
   check_read_watch (transport);
@@ -734,17 +740,27 @@
   if (watch == unix_transport->read_watch &&
       (flags & DBUS_WATCH_READABLE))
     {
+      dbus_bool_t auth_finished;
 #if 0
       _dbus_verbose ("handling read watch (%x)\n", flags);
 #endif
-      if (!do_authentication (transport, TRUE, FALSE))
+      if (!do_authentication (transport, TRUE, FALSE, &auth_finished))
         return FALSE;
-      
-      if (!do_reading (transport))
-        {
-          _dbus_verbose ("no memory to read\n");
-          return FALSE;
-        }
+
+      /* We don't want to do a read immediately following
+       * a successful authentication.  This is so we
+       * have a chance to propagate the authentication
+       * state further up.  Specifically, we need to
+       * process any pending data from the auth object.
+       */
+      if (!auth_finished)
+	{
+	  if (!do_reading (transport))
+	    {
+	      _dbus_verbose ("no memory to read\n");
+	      return FALSE;
+	    }
+	}
     }
   else if (watch == unix_transport->write_watch &&
            (flags & DBUS_WATCH_WRITABLE))
@@ -753,7 +769,7 @@
       _dbus_verbose ("handling write watch, messages_need_sending = %d\n",
                      transport->messages_need_sending);
 #endif
-      if (!do_authentication (transport, FALSE, TRUE))
+      if (!do_authentication (transport, FALSE, TRUE, NULL))
         return FALSE;
       
       if (!do_writing (transport))
@@ -922,10 +938,16 @@
             {
               dbus_bool_t need_read = (poll_fd.revents & _DBUS_POLLIN) > 0;
               dbus_bool_t need_write = (poll_fd.revents & _DBUS_POLLOUT) > 0;
+	      dbus_bool_t authentication_completed;
 
               _dbus_verbose ("in iteration, need_read=%d need_write=%d\n",
                              need_read, need_write);
-              do_authentication (transport, need_read, need_write);
+              do_authentication (transport, need_read, need_write,
+				 &authentication_completed);
+
+	      /* See comment in unix_handle_watch. */
+	      if (authentication_completed)
+		return;
                                  
               if (need_read && (flags & DBUS_ITERATION_DO_READING))
                 do_reading (transport);



More information about the dbus-commit mailing list