diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2016-02-26 00:28:05 +0100 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2016-02-26 19:59:17 +0100 |
commit | a2c575e34e6625a0813ebf57a100aafd314ec9ae (patch) | |
tree | 620c3b3c8f0892ad0c23e90e0c6c9ffdfd9ed604 /gdk/wayland/gdkselection-wayland.c | |
parent | ed3c87df7a09ba1e0145c6b912a58f4a056d2925 (diff) | |
download | gtk+-a2c575e34e6625a0813ebf57a100aafd314ec9ae.tar.gz |
wayland: Use the page size as the selection buffer size
And ensure we don't attempt to read EOF twice, once is enough.
Diffstat (limited to 'gdk/wayland/gdkselection-wayland.c')
-rw-r--r-- | gdk/wayland/gdkselection-wayland.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/gdk/wayland/gdkselection-wayland.c b/gdk/wayland/gdkselection-wayland.c index c5e0dc5dd2..9fcb31360c 100644 --- a/gdk/wayland/gdkselection-wayland.c +++ b/gdk/wayland/gdkselection-wayland.c @@ -18,6 +18,7 @@ #include "config.h" #include <fcntl.h> +#include <unistd.h> #include <gio/gunixinputstream.h> #include <gio/gunixoutputstream.h> @@ -224,25 +225,35 @@ selection_buffer_remove_requestor (SelectionBuffer *buffer, return TRUE; } +static inline glong +get_buffer_size (void) +{ + return sysconf (_SC_PAGESIZE); +} + static void selection_buffer_read_cb (GObject *object, GAsyncResult *result, gpointer user_data) { SelectionBuffer *buffer = user_data; + gboolean finished = TRUE; GError *error = NULL; GBytes *bytes; bytes = g_input_stream_read_bytes_finish (buffer->stream, result, &error); - if (bytes && g_bytes_get_size (bytes) > 0) + if (bytes) { + finished = g_bytes_get_size (bytes) < get_buffer_size (); selection_buffer_append_data (buffer, g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes)); - selection_buffer_read (buffer); g_bytes_unref (bytes); } + + if (!finished) + selection_buffer_read (buffer); else { if (error) @@ -256,9 +267,6 @@ selection_buffer_read_cb (GObject *object, g_input_stream_close (buffer->stream, NULL, NULL); g_clear_object (&buffer->stream); g_clear_object (&buffer->cancellable); - - if (bytes) - g_bytes_unref (bytes); } selection_buffer_unref (buffer); @@ -268,7 +276,8 @@ static void selection_buffer_read (SelectionBuffer *buffer) { selection_buffer_ref (buffer); - g_input_stream_read_bytes_async (buffer->stream, 1000, G_PRIORITY_DEFAULT, + g_input_stream_read_bytes_async (buffer->stream, get_buffer_size(), + G_PRIORITY_DEFAULT, buffer->cancellable, selection_buffer_read_cb, buffer); } |