Mercurial > vim
diff src/os_mswin.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 | 515db00c4676 |
children | 2e4877acfe0a |
line wrap: on
line diff
--- a/src/os_mswin.c +++ b/src/os_mswin.c @@ -2401,6 +2401,7 @@ serverSendToVim( char_u **result, /* Result of eval'ed expression */ void *ptarget, /* HWND of server */ int asExpr, /* Expression or keys? */ + int timeout, /* timeout in seconds or zero */ int silent) /* don't complain about no server */ { HWND target; @@ -2444,7 +2445,7 @@ serverSendToVim( return -1; if (asExpr) - retval = serverGetReply(target, &retcode, TRUE, TRUE); + retval = serverGetReply(target, &retcode, TRUE, TRUE, timeout); if (result == NULL) vim_free(retval); @@ -2521,14 +2522,17 @@ save_reply(HWND server, char_u *reply, i * if "wait" is TRUE block until a message arrives (or the server exits). */ char_u * -serverGetReply(HWND server, int *expr_res, int remove, int wait) +serverGetReply(HWND server, int *expr_res, int remove, int wait, int timeout) { int i; char_u *reply; reply_T *rep; int did_process = FALSE; + time_t start; + time_t now; /* When waiting, loop until the message waiting for is received. */ + time(&start); for (;;) { /* Reset this here, in case a message arrives while we are going @@ -2584,6 +2588,10 @@ serverGetReply(HWND server, int *expr_re #ifdef FEAT_TIMERS check_due_timer(); #endif + time(&now); + if (timeout > 0 && (now - start) >= timeout) + break; + /* Wait for a SendMessage() call to us. This could be the reply * we are waiting for. Use a timeout of a second, to catch the * situation that the server died unexpectedly. */