[mutter/wip/carlosg/incr-is-fubar: 10/11] x11: Don't exceed transfer size in INCR chunks



commit 06c602c7bb0974e1a0aa51161de140d6f73f47b1
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat Apr 11 17:21:20 2020 +0200

    x11: Don't exceed transfer size in INCR chunks
    
    The stream automatically flushes after data size exceeds the
    size we deem for INCR chunks, but we still try to copy it all.
    Actually limit the data we copy, and leave the rest for future
    INCR chunks.

 src/x11/meta-x11-selection-output-stream.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/src/x11/meta-x11-selection-output-stream.c b/src/x11/meta-x11-selection-output-stream.c
index 42abd99c1..877995ac1 100644
--- a/src/x11/meta-x11-selection-output-stream.c
+++ b/src/x11/meta-x11-selection-output-stream.c
@@ -199,7 +199,7 @@ meta_x11_selection_output_stream_perform_flush (MetaX11SelectionOutputStream *st
   MetaX11SelectionOutputStreamPrivate *priv =
     meta_x11_selection_output_stream_get_instance_private (stream);
   Display *xdisplay;
-  size_t element_size, n_elements;
+  size_t element_size, n_elements, max_size;
   gboolean first_chunk = FALSE;
   int error_code;
 
@@ -214,6 +214,7 @@ meta_x11_selection_output_stream_perform_flush (MetaX11SelectionOutputStream *st
 
   element_size = get_element_size (priv->format);
   n_elements = priv->data->len / element_size;
+  max_size = get_max_request_size (priv->x11_display);
 
   if (!priv->incr)
     first_chunk = TRUE;
@@ -243,6 +244,8 @@ meta_x11_selection_output_stream_perform_flush (MetaX11SelectionOutputStream *st
     }
   else
     {
+      size_t copy_n_elements;
+
       if (priv->data->len == 0)
         {
           priv->closing = FALSE;
@@ -255,6 +258,8 @@ meta_x11_selection_output_stream_perform_flush (MetaX11SelectionOutputStream *st
             priv->closing = TRUE;
         }
 
+      copy_n_elements = MIN (n_elements, max_size / element_size);
+
       XChangeProperty (xdisplay,
                        priv->xwindow,
                        priv->xproperty,
@@ -262,8 +267,8 @@ meta_x11_selection_output_stream_perform_flush (MetaX11SelectionOutputStream *st
                        priv->format,
                        PropModeReplace,
                        priv->data->data,
-                       n_elements);
-      g_byte_array_remove_range (priv->data, 0, n_elements * element_size);
+                       copy_n_elements);
+      g_byte_array_remove_range (priv->data, 0, copy_n_elements * element_size);
     }
 
   if (first_chunk)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]