diff src/if_xcmdsrv.c @ 11211:71311d899b42 v8.0.0492

patch 8.0.0492: a failing client-server request can make Vim hang commit https://github.com/vim/vim/commit/81b9d0bd5c705815e903e671e81b0b05828efd9c Author: Bram Moolenaar <Bram@vim.org> Date: Sun Mar 19 21:20:53 2017 +0100 patch 8.0.0492: a failing client-server request can make Vim hang Problem: A failing client-server request can make Vim hang. Solution: Add a timeout argument to functions that wait.
author Christian Brabandt <cb@256bit.org>
date Sun, 19 Mar 2017 21:30:05 +0100
parents 13544aa85dc0
children de1ae9d8ef57
line wrap: on
line diff
--- a/src/if_xcmdsrv.c
+++ b/src/if_xcmdsrv.c
@@ -373,6 +373,7 @@ serverSendToVim(
     char_u	**result,		/* Result of eval'ed expression */
     Window	*server,		/* Actual ID of receiving app */
     Bool	asExpr,			/* Interpret as keystrokes or expr ? */
+    int		timeout,		/* seconds to wait or zero */
     Bool	localLoop,		/* Throw away everything but result */
     int		silent)			/* don't complain about no server */
 {
@@ -485,7 +486,8 @@ serverSendToVim(
     pending.nextPtr = pendingCommands;
     pendingCommands = &pending;
 
-    ServerWait(dpy, w, WaitForPend, &pending, localLoop, 600);
+    ServerWait(dpy, w, WaitForPend, &pending, localLoop,
+						  timeout > 0 ? timeout : 600);
 
     /*
      * Unregister the information about the pending command
@@ -790,6 +792,7 @@ WaitForReply(void *p)
 
 /*
  * Wait for replies from id (win)
+ * When "timeout" is non-zero wait up to this many seconds.
  * Return 0 and the malloc'ed string when a reply is available.
  * Return -1 if the window becomes invalid while waiting.
  */
@@ -798,13 +801,15 @@ serverReadReply(
     Display	*dpy,
     Window	win,
     char_u	**str,
-    int		localLoop)
+    int		localLoop,
+    int		timeout)
 {
     int		len;
     char_u	*s;
     struct	ServerReply *p;
 
-    ServerWait(dpy, win, WaitForReply, &win, localLoop, -1);
+    ServerWait(dpy, win, WaitForReply, &win, localLoop,
+						   timeout > 0 ? timeout : -1);
 
     if ((p = ServerReplyFind(win, SROP_Find)) != NULL && p->strings.ga_len > 0)
     {