components/vim/vim72-patches/7.2.013
changeset 198 172fc01ce997
equal deleted inserted replaced
197:fd801ec0737c 198:172fc01ce997
       
     1 To: [email protected]
       
     2 Subject: Patch 7.2.013
       
     3 Fcc: outbox
       
     4 From: Bram Moolenaar <[email protected]>
       
     5 Mime-Version: 1.0
       
     6 Content-Type: text/plain; charset=ISO-8859-1
       
     7 Content-Transfer-Encoding: 8bit
       
     8 ------------
       
     9 
       
    10 Patch 7.2.013
       
    11 Problem:    While waiting for the X selection Vim consumes a lot of CPU time
       
    12 	    and hangs until a response is received.
       
    13 Solution:   Sleep a bit when the selection event hasn't been received yet.
       
    14 	    Time out after a couple of seconds to avoid a hang when the
       
    15 	    selection owner isn't responding.
       
    16 Files:	    src/ui.c
       
    17 
       
    18 
       
    19 *** ../vim-7.2.012/src/ui.c	Mon Jul 14 21:47:49 2008
       
    20 --- src/ui.c	Sun Sep  7 16:54:35 2008
       
    21 ***************
       
    22 *** 2110,2115 ****
       
    23 --- 2110,2117 ----
       
    24       int		i;
       
    25       int		nbytes = 0;
       
    26       char_u	*buffer;
       
    27 +     time_t	start_time;
       
    28 +     int		timed_out = FALSE;
       
    29   
       
    30       for (i =
       
    31   #ifdef FEAT_MBYTE
       
    32 ***************
       
    33 *** 2129,2134 ****
       
    34 --- 2131,2137 ----
       
    35   	    case 3:  type = text_atom;		break;
       
    36   	    default: type = XA_STRING;
       
    37   	}
       
    38 + 	success = FALSE;
       
    39   	XtGetSelectionValue(myShell, cbd->sel_atom, type,
       
    40   	    clip_x11_request_selection_cb, (XtPointer)&success, CurrentTime);
       
    41   
       
    42 ***************
       
    43 *** 2141,2167 ****
       
    44   	 * characters, then they will appear before the one that requested the
       
    45   	 * paste!  Don't worry, we will catch up with any other events later.
       
    46   	 */
       
    47   	for (;;)
       
    48   	{
       
    49   	    if (XCheckTypedEvent(dpy, SelectionNotify, &event))
       
    50   		break;
       
    51   	    if (XCheckTypedEvent(dpy, SelectionRequest, &event))
       
    52   		/* We may get a SelectionRequest here and if we don't handle
       
    53   		 * it we hang.  KDE klipper does this, for example. */
       
    54   		XtDispatchEvent(&event);
       
    55   
       
    56   	    /* Do we need this?  Probably not. */
       
    57   	    XSync(dpy, False);
       
    58   
       
    59 ! 	    /* Bernhard Walle solved a slow paste response in an X terminal by
       
    60 ! 	     * adding: usleep(10000); here. */
       
    61   	}
       
    62   
       
    63 - 	/* this is where clip_x11_request_selection_cb() is actually called */
       
    64 - 	XtDispatchEvent(&event);
       
    65 - 
       
    66   	if (success)
       
    67   	    return;
       
    68       }
       
    69   
       
    70       /* Final fallback position - use the X CUT_BUFFER0 store */
       
    71 --- 2144,2189 ----
       
    72   	 * characters, then they will appear before the one that requested the
       
    73   	 * paste!  Don't worry, we will catch up with any other events later.
       
    74   	 */
       
    75 + 	start_time = time(NULL);
       
    76   	for (;;)
       
    77   	{
       
    78   	    if (XCheckTypedEvent(dpy, SelectionNotify, &event))
       
    79 + 	    {
       
    80 + 		/* this is where clip_x11_request_selection_cb() is actually
       
    81 + 		 * called */
       
    82 + 		XtDispatchEvent(&event);
       
    83   		break;
       
    84 + 	    }
       
    85   	    if (XCheckTypedEvent(dpy, SelectionRequest, &event))
       
    86   		/* We may get a SelectionRequest here and if we don't handle
       
    87   		 * it we hang.  KDE klipper does this, for example. */
       
    88   		XtDispatchEvent(&event);
       
    89   
       
    90 + 	    /* Time out after 2 to 3 seconds to avoid that we hang when the
       
    91 + 	     * other process doesn't respond.  Note that the SelectionNotify
       
    92 + 	     * event may still come later when the selection owner comes back
       
    93 + 	     * to life and the text gets inserted unexpectedly (by xterm).
       
    94 + 	     * Don't know how to avoid that :-(. */
       
    95 + 	    if (time(NULL) > start_time + 2)
       
    96 + 	    {
       
    97 + 		timed_out = TRUE;
       
    98 + 		break;
       
    99 + 	    }
       
   100 + 
       
   101   	    /* Do we need this?  Probably not. */
       
   102   	    XSync(dpy, False);
       
   103   
       
   104 ! 	    /* Wait for 1 msec to avoid that we eat up all CPU time. */
       
   105 ! 	    ui_delay(1L, TRUE);
       
   106   	}
       
   107   
       
   108   	if (success)
       
   109   	    return;
       
   110 + 
       
   111 + 	/* don't do a retry with another type after timing out, otherwise we
       
   112 + 	 * hang for 15 seconds. */
       
   113 + 	if (timed_out)
       
   114 + 	    break;
       
   115       }
       
   116   
       
   117       /* Final fallback position - use the X CUT_BUFFER0 store */
       
   118 *** ../vim-7.2.012/src/version.c	Sun Sep  7 15:49:45 2008
       
   119 --- src/version.c	Sun Sep  7 21:45:55 2008
       
   120 ***************
       
   121 *** 678,679 ****
       
   122 --- 678,681 ----
       
   123   {   /* Add new patch number below this line */
       
   124 + /**/
       
   125 +     13,
       
   126   /**/
       
   127 
       
   128 -- 
       
   129 The users that I support would double-click on a landmine to find out
       
   130 what happens.				-- A system administrator
       
   131 
       
   132  /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
       
   133 ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
       
   134 \\\        download, build and distribute -- http://www.A-A-P.org        ///
       
   135  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///