Pool sizes redefined and cleanup
[platform/upstream/dbus.git] / dbus / dbus-transport-socket.c
index dc9933d..e7598ae 100644 (file)
@@ -21,6 +21,7 @@
  *
  */
 
+#include <config.h>
 #include "dbus-internals.h"
 #include "dbus-connection-internal.h"
 #include "dbus-nonce.h"
@@ -28,6 +29,8 @@
 #include "dbus-transport-protected.h"
 #include "dbus-watch.h"
 #include "dbus-credentials.h"
+#include <stdio.h>  //todo to remove
+
 
 /**
  * @defgroup DBusTransportSocket DBusTransport implementations for sockets
@@ -72,7 +75,7 @@ free_watches (DBusTransport *transport)
 {
   DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport;
 
-  _dbus_verbose ("%s start\n", _DBUS_FUNCTION_NAME);
+  _dbus_verbose ("start\n");
   
   if (socket_transport->read_watch)
     {
@@ -94,7 +97,7 @@ free_watches (DBusTransport *transport)
       socket_transport->write_watch = NULL;
     }
 
-  _dbus_verbose ("%s end\n", _DBUS_FUNCTION_NAME);
+  _dbus_verbose ("end\n");
 }
 
 static void
@@ -102,7 +105,7 @@ socket_finalize (DBusTransport *transport)
 {
   DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport;
 
-  _dbus_verbose ("%s\n", _DBUS_FUNCTION_NAME);
+  _dbus_verbose ("\n");
   
   free_watches (transport);
 
@@ -176,8 +179,7 @@ check_read_watch (DBusTransport *transport)
   DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport;
   dbus_bool_t need_read_watch;
 
-  _dbus_verbose ("%s: fd = %d\n",
-                 _DBUS_FUNCTION_NAME, socket_transport->fd);
+  _dbus_verbose ("fd = %d\n",socket_transport->fd);
   
   if (transport->connection == NULL)
     return;
@@ -529,6 +531,8 @@ do_writing (DBusTransport *transport)
       int header_len, body_len;
       int total_bytes_to_write;
       
+//      int i;
+
       if (total > socket_transport->max_bytes_written_per_iteration)
         {
           _dbus_verbose ("%d bytes exceeds %d bytes written per iteration, returning\n",
@@ -550,6 +554,32 @@ do_writing (DBusTransport *transport)
       header_len = _dbus_string_get_length (header);
       body_len = _dbus_string_get_length (body);
 
+  /*    fprintf (stderr, "\nheader:\n");  //todo for test - to remove together wit int i declaration above
+      for(i=0; i < header_len; i++)
+      {
+       fprintf (stderr, "%02x", _dbus_string_get_byte(header,i));
+      }
+      fprintf (stderr,"\n");
+      for(i=0; i < header_len; i++)
+      {
+       fprintf (stderr, "%c", _dbus_string_get_byte(header,i));
+      }
+      fprintf (stderr, "\nret size: %u, i: %u\n", header_len, i);
+
+
+      fprintf (stderr, "\nbody:\n");
+      for(i=0; i < body_len; i++)
+      {
+       fprintf (stderr, "%02x", _dbus_string_get_byte(body,i));
+      }
+      fprintf (stderr, "\nret size: %u, i: %u\n", body_len, i);
+      fprintf (stderr,"\n");
+      for(i=0; i < body_len; i++)
+      {
+       fprintf (stderr, "%c", _dbus_string_get_byte(body,i));
+      }
+      fprintf (stderr, "\nret size: %u, i: %u\n", body_len, i);*/
+
       if (_dbus_auth_needs_encoding (transport->auth))
         {
           /* Does fd passing even make sense with encoded data? */
@@ -677,8 +707,8 @@ do_writing (DBusTransport *transport)
               _dbus_string_set_length (&socket_transport->encoded_outgoing, 0);
               _dbus_string_compact (&socket_transport->encoded_outgoing, 2048);
 
-              _dbus_connection_message_sent (transport->connection,
-                                             message);
+              _dbus_connection_message_sent_unlocked (transport->connection,
+                                                      message);
             }
         }
     }
@@ -700,8 +730,7 @@ do_reading (DBusTransport *transport)
   int total;
   dbus_bool_t oom;
 
-  _dbus_verbose ("%s: fd = %d\n", _DBUS_FUNCTION_NAME,
-                 socket_transport->fd);
+  _dbus_verbose ("fd = %d\n",socket_transport->fd);
   
   /* No messages without authentication! */
   if (!_dbus_transport_get_is_authenticated (transport))
@@ -816,7 +845,7 @@ do_reading (DBusTransport *transport)
                                           buffer,
                                           bytes_read < 0 ? 0 : bytes_read);
     }
-  
+
   if (bytes_read < 0)
     {
       /* EINTR already handled for us */
@@ -983,7 +1012,7 @@ socket_disconnect (DBusTransport *transport)
 {
   DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport;
 
-  _dbus_verbose ("%s\n", _DBUS_FUNCTION_NAME);
+  _dbus_verbose ("\n");
   
   free_watches (transport);
   
@@ -1118,7 +1147,7 @@ socket_do_iteration (DBusTransport *transport,
        */
       if (flags & DBUS_ITERATION_BLOCK)
         {
-          _dbus_verbose ("unlock %s pre poll\n", _DBUS_FUNCTION_NAME);
+          _dbus_verbose ("unlock pre poll\n");
           _dbus_connection_unlock (transport->connection);
         }
       
@@ -1130,7 +1159,7 @@ socket_do_iteration (DBusTransport *transport,
 
       if (flags & DBUS_ITERATION_BLOCK)
         {
-          _dbus_verbose ("lock %s post poll\n", _DBUS_FUNCTION_NAME);
+          _dbus_verbose ("lock post poll\n");
           _dbus_connection_lock (transport->connection);
         }
       
@@ -1279,8 +1308,10 @@ _dbus_transport_new_for_socket (int               fd,
   return (DBusTransport*) socket_transport;
 
  failed_4:
+  _dbus_watch_invalidate (socket_transport->read_watch);
   _dbus_watch_unref (socket_transport->read_watch);
  failed_3:
+  _dbus_watch_invalidate (socket_transport->write_watch);
   _dbus_watch_unref (socket_transport->write_watch);
  failed_2:
   _dbus_string_free (&socket_transport->encoded_incoming);
@@ -1336,12 +1367,12 @@ _dbus_transport_new_for_tcp_socket (const char     *host,
     goto error;
 
   if (family != NULL &&
-      (!_dbus_string_append (&address, "family=") ||
+      (!_dbus_string_append (&address, ",family=") ||
        !_dbus_string_append (&address, family)))
     goto error;
 
   if (noncefile != NULL &&
-      (!_dbus_string_append (&address, "noncefile=") ||
+      (!_dbus_string_append (&address, ",noncefile=") ||
        !_dbus_string_append (&address, noncefile)))
     goto error;
 
@@ -1357,16 +1388,14 @@ _dbus_transport_new_for_tcp_socket (const char     *host,
                  host, port);
   
   transport = _dbus_transport_new_for_socket (fd, NULL, &address);
+  _dbus_string_free (&address);
   if (transport == NULL)
     {
       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
       _dbus_close_socket (fd, NULL);
-      _dbus_string_free (&address);
       fd = -1;
     }
 
-  _dbus_string_free (&address);
-  
   return transport;
 
 error: