wayland: Use the page size as the selection buffer size
And ensure we don't attempt to read EOF twice, once is enough.
This commit is contained in:
parent
ed3c87df7a
commit
a2c575e34e
@ -18,6 +18,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <gio/gunixinputstream.h>
|
#include <gio/gunixinputstream.h>
|
||||||
#include <gio/gunixoutputstream.h>
|
#include <gio/gunixoutputstream.h>
|
||||||
@ -224,25 +225,35 @@ selection_buffer_remove_requestor (SelectionBuffer *buffer,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline glong
|
||||||
|
get_buffer_size (void)
|
||||||
|
{
|
||||||
|
return sysconf (_SC_PAGESIZE);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
selection_buffer_read_cb (GObject *object,
|
selection_buffer_read_cb (GObject *object,
|
||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
SelectionBuffer *buffer = user_data;
|
SelectionBuffer *buffer = user_data;
|
||||||
|
gboolean finished = TRUE;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
GBytes *bytes;
|
GBytes *bytes;
|
||||||
|
|
||||||
bytes = g_input_stream_read_bytes_finish (buffer->stream, result, &error);
|
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,
|
selection_buffer_append_data (buffer,
|
||||||
g_bytes_get_data (bytes, NULL),
|
g_bytes_get_data (bytes, NULL),
|
||||||
g_bytes_get_size (bytes));
|
g_bytes_get_size (bytes));
|
||||||
selection_buffer_read (buffer);
|
|
||||||
g_bytes_unref (bytes);
|
g_bytes_unref (bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!finished)
|
||||||
|
selection_buffer_read (buffer);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (error)
|
if (error)
|
||||||
@ -256,9 +267,6 @@ selection_buffer_read_cb (GObject *object,
|
|||||||
g_input_stream_close (buffer->stream, NULL, NULL);
|
g_input_stream_close (buffer->stream, NULL, NULL);
|
||||||
g_clear_object (&buffer->stream);
|
g_clear_object (&buffer->stream);
|
||||||
g_clear_object (&buffer->cancellable);
|
g_clear_object (&buffer->cancellable);
|
||||||
|
|
||||||
if (bytes)
|
|
||||||
g_bytes_unref (bytes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
selection_buffer_unref (buffer);
|
selection_buffer_unref (buffer);
|
||||||
@ -268,7 +276,8 @@ static void
|
|||||||
selection_buffer_read (SelectionBuffer *buffer)
|
selection_buffer_read (SelectionBuffer *buffer)
|
||||||
{
|
{
|
||||||
selection_buffer_ref (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->cancellable, selection_buffer_read_cb,
|
||||||
buffer);
|
buffer);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user