home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.2 / 7.2.013 < prev    next >
Encoding:
Internet Message Format  |  2008-09-06  |  4.1 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 7.2.013
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  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.       if (success)
  66.           return;
  67.       }
  68.   
  69.       /* Final fallback position - use the X CUT_BUFFER0 store */
  70. --- 2144,2189 ----
  71.        * characters, then they will appear before the one that requested the
  72.        * paste!  Don't worry, we will catch up with any other events later.
  73.        */
  74. +     start_time = time(NULL);
  75.       for (;;)
  76.       {
  77.           if (XCheckTypedEvent(dpy, SelectionNotify, &event))
  78. +         {
  79. +         /* this is where clip_x11_request_selection_cb() is actually
  80. +          * called */
  81. +         XtDispatchEvent(&event);
  82.           break;
  83. +         }
  84.           if (XCheckTypedEvent(dpy, SelectionRequest, &event))
  85.           /* We may get a SelectionRequest here and if we don't handle
  86.            * it we hang.  KDE klipper does this, for example. */
  87.           XtDispatchEvent(&event);
  88.   
  89. +         /* Time out after 2 to 3 seconds to avoid that we hang when the
  90. +          * other process doesn't respond.  Note that the SelectionNotify
  91. +          * event may still come later when the selection owner comes back
  92. +          * to life and the text gets inserted unexpectedly (by xterm).
  93. +          * Don't know how to avoid that :-(. */
  94. +         if (time(NULL) > start_time + 2)
  95. +         {
  96. +         timed_out = TRUE;
  97. +         break;
  98. +         }
  99.           /* Do we need this?  Probably not. */
  100.           XSync(dpy, False);
  101.   
  102. !         /* Wait for 1 msec to avoid that we eat up all CPU time. */
  103. !         ui_delay(1L, TRUE);
  104.       }
  105.   
  106.       if (success)
  107.           return;
  108. +     /* don't do a retry with another type after timing out, otherwise we
  109. +      * hang for 15 seconds. */
  110. +     if (timed_out)
  111. +         break;
  112.       }
  113.   
  114.       /* Final fallback position - use the X CUT_BUFFER0 store */
  115. *** ../vim-7.2.012/src/version.c    Sun Sep  7 15:49:45 2008
  116. --- src/version.c    Sun Sep  7 21:45:55 2008
  117. ***************
  118. *** 678,679 ****
  119. --- 678,681 ----
  120.   {   /* Add new patch number below this line */
  121. + /**/
  122. +     13,
  123.   /**/
  124.  
  125. -- 
  126. The users that I support would double-click on a landmine to find out
  127. what happens.                -- A system administrator
  128.  
  129.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  130. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  131. \\\        download, build and distribute -- http://www.A-A-P.org        ///
  132.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  133.