diff src/channel.c @ 10406:42911b233245 v8.0.0097

commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Nov 24 17:22:50 2016 +0100 patch 8.0.0097 Problem: When a channel callback consumes a lot of time Vim becomes unresponsive. (skywind) Solution: Bail out of checking channel readahead after 100 msec.
author Christian Brabandt <cb@256bit.org>
date Thu, 24 Nov 2016 17:30:04 +0100
parents d3f0946b4a80
children 56cb9538386c
line wrap: on
line diff
--- a/src/channel.c
+++ b/src/channel.c
@@ -3815,6 +3815,11 @@ channel_parse_messages(void)
     int		ret = FALSE;
     int		r;
     ch_part_T	part = PART_SOCK;
+#ifdef ELAPSED_FUNC
+    ELAPSED_TYPE  start_tv;
+
+    ELAPSED_INIT(start_tv);
+#endif
 
     ++safe_to_invoke_callback;
 
@@ -3859,7 +3864,14 @@ channel_parse_messages(void)
 	    r = may_invoke_callback(channel, part);
 	    if (r == OK)
 		ret = TRUE;
-	    if (channel_unref(channel) || r == OK)
+	    if (channel_unref(channel) || (r == OK
+#ifdef ELAPSED_FUNC
+			/* Limit the time we loop here to 100 msec, otherwise
+			 * Vim becomes unresponsive when the callback takes
+			 * more than a bit of time. */
+			&& ELAPSED_FUNC(start_tv) < 100L
+#endif
+			))
 	    {
 		/* channel was freed or something was done, start over */
 		channel = first_channel;