From b033b481fa9bb4fb76bc67ed595ce53bdef23969 Mon Sep 17 00:00:00 2001 From: ichizok Date: Wed, 3 Aug 2022 18:58:49 +0900 Subject: [PATCH] Fix `unused-but-set-variable` error when built on 12.x Add `timeout` argument to serverReadReply() --- src/MacVim/MMBackend.h | 2 +- src/MacVim/MMBackend.m | 9 ++++++--- src/MacVim/gui_macvim.m | 5 +++-- src/clientserver.c | 4 ++-- src/proto/gui_macvim.pro | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/MacVim/MMBackend.h b/src/MacVim/MMBackend.h index 021955f3f8..b05c9e9f95 100644 --- a/src/MacVim/MMBackend.h +++ b/src/MacVim/MMBackend.h @@ -143,7 +143,7 @@ silent:(BOOL)silent; - (NSArray *)serverList; - (NSString *)peekForReplyOnPort:(int)port; -- (NSString *)waitForReplyOnPort:(int)port; +- (NSString *)waitForReplyOnPort:(int)port timeout:(NSTimeInterval)timeout; - (BOOL)sendReply:(NSString *)reply toPort:(int)port; - (BOOL)waitForAck; diff --git a/src/MacVim/MMBackend.m b/src/MacVim/MMBackend.m index 60644a4d33..71735cf2ae 100644 --- a/src/MacVim/MMBackend.m +++ b/src/MacVim/MMBackend.m @@ -1582,7 +1582,7 @@ extern GuiFont gui_mch_retain_font(GuiFont font); return nil; } -- (NSString *)waitForReplyOnPort:(int)port +- (NSString *)waitForReplyOnPort:(int)port timeout:(NSTimeInterval)timeout { ASLogDebug(@"port=%d", port); @@ -1593,13 +1593,16 @@ extern GuiFont gui_mch_retain_font(GuiFont font); NSNumber *key = [NSNumber numberWithInt:port]; NSMutableArray *replies = nil; NSString *reply = nil; + NSDate *limitDate = timeout > 0 + ? [NSDate dateWithTimeIntervalSinceNow:timeout] : [NSDate distantFuture]; // Wait for reply as long as the connection to the server is valid (unless // user interrupts wait with Ctrl-C). while (!got_int && [conn isValid] && - !(replies = [serverReplyDict objectForKey:key])) { + !(replies = [serverReplyDict objectForKey:key]) && + (timeout <= 0 || [limitDate timeIntervalSinceNow] > 0)) { [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode - beforeDate:[NSDate distantFuture]]; + beforeDate:limitDate]; } if (replies) { diff --git a/src/MacVim/gui_macvim.m b/src/MacVim/gui_macvim.m index 9d5410980e..e11c2b7396 100644 --- a/src/MacVim/gui_macvim.m +++ b/src/MacVim/gui_macvim.m @@ -2118,9 +2118,10 @@ serverPeekReply(int port, char_u **str) * Return -1 on error. */ int -serverReadReply(int port, char_u **str) +serverReadReply(int port, char_u **str, int timeout) { - NSString *reply = [[MMBackend sharedInstance] waitForReplyOnPort:port]; + NSString *reply = [[MMBackend sharedInstance] waitForReplyOnPort:port + timeout:timeout]; if (reply && str) { *str = [reply vimStringSave]; return 0; diff --git a/src/clientserver.c b/src/clientserver.c index 10b111cc5b..9c451635b5 100644 --- a/src/clientserver.c +++ b/src/clientserver.c @@ -457,7 +457,7 @@ cmdsrv_main( if (p == NULL) break; # elif defined(MAC_CLIENTSERVER) - if (serverReadReply(srv, &p) < 0) + if (serverReadReply(srv, &p, 0) < 0) break; # else if (serverReadReply(xterm_dpy, srv, &p, TRUE, -1) < 0) @@ -934,7 +934,7 @@ f_remote_read(typval_T *argvars UNUSED, typval_T *rettv) r = serverGetReply((HWND)n, FALSE, TRUE, TRUE, timeout); if (r == NULL) # elif defined(MAC_CLIENTSERVER) - if (serverReadReply(serverStrToPort(serverid), &r) < 0) + if (serverReadReply(serverStrToPort(serverid), &r, timeout) < 0) # else if (check_connection() == FAIL || serverReadReply(X_DISPLAY, serverStrToWin(serverid), diff --git a/src/proto/gui_macvim.pro b/src/proto/gui_macvim.pro index 549083f99e..bf0ccff3e2 100644 --- a/src/proto/gui_macvim.pro +++ b/src/proto/gui_macvim.pro @@ -91,7 +91,7 @@ int serverSendToVim(char_u *name, char_u *cmd, char_u **result, int *server, int char_u *serverGetVimNames(void); int serverStrToPort(char_u *str); int serverPeekReply(int port, char_u **str); -int serverReadReply(int port, char_u **str); +int serverReadReply(int port, char_u **str, int timeout); int serverSendReply(char_u *serverid, char_u *str); void gui_mch_enter_fullscreen(guicolor_T bg);