diff options
author | Rodrigo Moya <rodrigo.moya@collabora.co.uk> | 2012-06-05 14:24:56 +0200 |
---|---|---|
committer | Rodrigo Moya <rodrigo@gnome-db.org> | 2012-06-05 14:24:56 +0200 |
commit | 7b326031a11eecb56ba0cb6ef72fdb78609a27e7 (patch) | |
tree | 53edb2b0690b7670129c8df90e6e604547eb4e97 | |
parent | 14ac9b370b45af68a77e62c834bcd6fb46acabb9 (diff) | |
download | dbus-7b326031a11eecb56ba0cb6ef72fdb78609a27e7.tar.gz |
Get available bytes with ioctl(FIONREAD) and use that to read the next message
-rw-r--r-- | dbus/dbus-transport-socket.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/dbus/dbus-transport-socket.c b/dbus/dbus-transport-socket.c index 3192c8b3..11df7655 100644 --- a/dbus/dbus-transport-socket.c +++ b/dbus/dbus-transport-socket.c @@ -22,6 +22,7 @@ */ #include <config.h> +#include <sys/ioctl.h> #include "dbus-internals.h" #include "dbus-connection-internal.h" #include "dbus-nonce.h" @@ -740,7 +741,7 @@ do_reading (DBusTransport *transport) { DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport; DBusString *buffer; - int bytes_read; + int bytes_read, bytes_available; int total; dbus_bool_t oom; @@ -774,7 +775,12 @@ do_reading (DBusTransport *transport) if (!dbus_watch_get_enabled (socket_transport->read_watch)) return TRUE; - + + if (ioctl (socket_transport->fd, FIONREAD, &bytes_available) < 0) + bytes_available = socket_transport->max_bytes_read_per_iteration; + else if (bytes_available < socket_transport->max_bytes_read_per_iteration) + bytes_available = socket_transport->max_bytes_read_per_iteration; + if (_dbus_auth_needs_decoding (transport->auth)) { /* Does fd passing even make sense with encoded data? */ @@ -785,7 +791,7 @@ do_reading (DBusTransport *transport) else bytes_read = _dbus_read_socket (socket_transport->fd, &socket_transport->encoded_incoming, - socket_transport->max_bytes_read_per_iteration); + bytes_available); _dbus_assert (_dbus_string_get_length (&socket_transport->encoded_incoming) == bytes_read); @@ -840,7 +846,7 @@ do_reading (DBusTransport *transport) bytes_read = _dbus_read_socket_with_unix_fds(socket_transport->fd, buffer, - socket_transport->max_bytes_read_per_iteration, + bytes_available, fds, &n_fds); if (bytes_read >= 0 && n_fds > 0) @@ -852,7 +858,7 @@ do_reading (DBusTransport *transport) #endif { bytes_read = _dbus_read_socket (socket_transport->fd, - buffer, socket_transport->max_bytes_read_per_iteration); + buffer, bytes_available); } _dbus_message_loader_return_buffer (transport->loader, |