From f12d983deab06b0408781d7a6c2f8970d765b723 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Fri, 29 Jan 2016 21:11:25 +0100 Subject: patch 7.4.1195 Problem: The channel feature does not work in the MS-Windows console. Solution: Add win32 console support. (Yasuhiro Matsumoto) --- src/channel.c | 12 ++++++------ src/gui_w32.c | 23 +---------------------- src/os_mswin.c | 23 ++++++++++++++++++++++- src/os_win32.c | 19 +++++++++++++++++++ src/proto/gui_w32.pro | 1 - src/proto/os_mswin.pro | 1 + src/version.c | 2 ++ src/vim.h | 2 ++ 8 files changed, 53 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/channel.c b/src/channel.c index def6833136..46c45b696a 100644 --- a/src/channel.c +++ b/src/channel.c @@ -91,7 +91,7 @@ typedef struct { #ifdef FEAT_GUI_GTK gint ch_inputHandler; /* Cookie for input */ #endif -#ifdef FEAT_GUI_W32 +#ifdef WIN32 int ch_inputHandler; /* simply ret.value of WSAAsyncSelect() */ #endif @@ -279,14 +279,14 @@ channel_open(char *hostname, int port_in, void (*close_cb)(void)) int sd; struct sockaddr_in server; struct hostent * host; -#ifdef FEAT_GUI_W32 +#ifdef WIN32 u_short port = port_in; #else int port = port_in; #endif int idx; -#ifdef FEAT_GUI_W32 +#ifdef WIN32 channel_init_winsock(); #endif @@ -861,7 +861,7 @@ channel_read_block(int idx) return channel_get(idx); } -# if defined(FEAT_GUI_W32) || defined(PROTO) +# if defined(WIN32) || defined(PROTO) /* * Lookup the channel index from the socket. * Returns -1 when the socket isn't found. @@ -965,7 +965,7 @@ channel_poll_check(int ret_in, void *fds_in) } # endif /* UNIX && !HAVE_SELECT */ -# if (defined(UNIX) && defined(HAVE_SELECT)) || defined(PROTO) +# if (!defined(FEAT_GUI_W32) && defined(HAVE_SELECT)) || defined(PROTO) /* * The type of "rfds" is hidden to avoid problems with the function proto. */ @@ -1007,6 +1007,6 @@ channel_select_check(int ret_in, void *rfds_in) return ret; } -# endif /* UNIX && HAVE_SELECT */ +# endif /* !FEAT_GUI_W32 && HAVE_SELECT */ #endif /* FEAT_CHANNEL */ diff --git a/src/gui_w32.c b/src/gui_w32.c index ecc1fab41f..88b89c6b3c 100644 --- a/src/gui_w32.c +++ b/src/gui_w32.c @@ -553,9 +553,6 @@ typedef BOOL (WINAPI *TGetMonitorInfo)(_HMONITOR, _MONITORINFO *); static TMonitorFromWindow pMonitorFromWindow = NULL; static TGetMonitorInfo pGetMonitorInfo = NULL; static HANDLE user32_lib = NULL; -#ifdef FEAT_CHANNEL -int WSInitialized = FALSE; /* WinSock is initialized */ -#endif /* * Return TRUE when running under Windows NT 3.x or Win32s, both of which have * less fancy GUI APIs. @@ -844,6 +841,7 @@ _OnWindowPosChanged( const LPWINDOWPOS lpwpos) { static int x = 0, y = 0, cx = 0, cy = 0; + extern int WSInitialized; if (WSInitialized && (lpwpos->x != x || lpwpos->y != y || lpwpos->cx != cx || lpwpos->cy != cy)) @@ -5049,22 +5047,3 @@ netbeans_draw_multisign_indicator(int row) SetPixel(s_hdc, x+2, y, gui.currFgColor); } #endif - -#if defined(FEAT_CHANNEL) || defined(PROTO) -/* - * Initialize the Winsock dll. - */ - void -channel_init_winsock() -{ - WSADATA wsaData; - int wsaerr; - - if (WSInitialized) - return; - - wsaerr = WSAStartup(MAKEWORD(2, 2), &wsaData); - if (wsaerr == 0) - WSInitialized = TRUE; -} -#endif diff --git a/src/os_mswin.c b/src/os_mswin.c index ed7aa834d4..16268920e3 100644 --- a/src/os_mswin.c +++ b/src/os_mswin.c @@ -161,7 +161,9 @@ extern HWND s_hwnd; static HWND s_hwnd = 0; /* console window handle, set by GetConsoleHwnd() */ #endif -extern int WSInitialized; +#ifdef FEAT_CHANNEL +int WSInitialized = FALSE; /* WinSock is initialized */ +#endif /* Don't generate prototypes here, because some systems do have these * functions. */ @@ -3093,3 +3095,22 @@ theend: } #endif /* defined(FEAT_GUI) || defined(FEAT_PRINTER) */ + +#if defined(FEAT_CHANNEL) || defined(PROTO) +/* + * Initialize the Winsock dll. + */ + void +channel_init_winsock() +{ + WSADATA wsaData; + int wsaerr; + + if (WSInitialized) + return; + + wsaerr = WSAStartup(MAKEWORD(2, 2), &wsaData); + if (wsaerr == 0) + WSInitialized = TRUE; +} +#endif diff --git a/src/os_win32.c b/src/os_win32.c index be7bd95b58..5a84824d36 100644 --- a/src/os_win32.c +++ b/src/os_win32.c @@ -1443,6 +1443,11 @@ WaitForChar(long msec) INPUT_RECORD ir; DWORD cRecords; WCHAR ch, ch2; +#ifdef FEAT_CHANNEL + int ret; + fd_set rfds; + int maxfd; +#endif if (msec > 0) /* Wait until the specified time has elapsed. */ @@ -1459,9 +1464,22 @@ WaitForChar(long msec) #ifdef FEAT_MZSCHEME mzvim_check_threads(); #endif + #ifdef FEAT_CLIENTSERVER serverProcessPendingMessages(); #endif + +#ifdef FEAT_CHANNEL + FD_ZERO(&rfds); + maxfd = channel_select_setup(-1, &rfds); + if (maxfd >= 0) + { + ret = select(maxfd + 1, &rfds, NULL, NULL, NULL); + if (ret > 0 && channel_select_check(ret, &rfds) > 0) + return TRUE; + } +#endif + if (0 #ifdef FEAT_MOUSE || g_nMouseClick != -1 @@ -1562,6 +1580,7 @@ WaitForChar(long msec) if (input_available()) return TRUE; #endif + return FALSE; } diff --git a/src/proto/gui_w32.pro b/src/proto/gui_w32.pro index 57c6238f87..c8411f96cf 100644 --- a/src/proto/gui_w32.pro +++ b/src/proto/gui_w32.pro @@ -96,5 +96,4 @@ void gui_mch_post_balloon(BalloonEval *beval, char_u *mesg); BalloonEval *gui_mch_create_beval_area(void *target, char_u *mesg, void (*mesgCB)(BalloonEval *, int), void *clientData); void gui_mch_destroy_beval_area(BalloonEval *beval); void netbeans_draw_multisign_indicator(int row); -void channel_init_winsock(void); /* vim: set ft=c : */ diff --git a/src/proto/os_mswin.pro b/src/proto/os_mswin.pro index ed2176eeec..333ba76c53 100644 --- a/src/proto/os_mswin.pro +++ b/src/proto/os_mswin.pro @@ -50,4 +50,5 @@ char_u *serverGetReply(HWND server, int *expr_res, int remove, int wait); void serverProcessPendingMessages(void); char *charset_id2name(int id); int get_logfont(LOGFONT *lf, char_u *name, HDC printer_dc, int verbose); +void channel_init_winsock(void); /* vim: set ft=c : */ diff --git a/src/version.c b/src/version.c index c246ed4bcb..54a88c8130 100644 --- a/src/version.c +++ b/src/version.c @@ -746,6 +746,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1195, /**/ 1194, /**/ diff --git a/src/vim.h b/src/vim.h index e7a5f58421..b8de4ae3e8 100644 --- a/src/vim.h +++ b/src/vim.h @@ -530,6 +530,8 @@ typedef unsigned long u8char_T; /* long should be 32 bits or more */ # ifdef HAVE_SYS_POLL_H # include # define HAVE_POLL +# elif defined(WIN32) && !defined(FEAT_GUI_W32) +# define HAVE_SELECT # else # ifdef HAVE_POLL_H # include -- cgit v1.2.3