changeset 7797:0d46cea25641 v7.4.1195

commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jan 29 21:11:25 2016 +0100 patch 7.4.1195 Problem: The channel feature does not work in the MS-Windows console. Solution: Add win32 console support. (Yasuhiro Matsumoto)
author Christian Brabandt <cb@256bit.org>
date Fri, 29 Jan 2016 21:15:05 +0100
parents acda999cbbb3
children c8a2382de513
files src/channel.c src/gui_w32.c src/os_mswin.c src/os_win32.c src/proto/gui_w32.pro src/proto/os_mswin.pro src/version.c src/vim.h
diffstat 8 files changed, 53 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- 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
     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
 }
 # 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 *r
 
     return ret;
 }
-# endif /* UNIX && HAVE_SELECT */
+# endif /* !FEAT_GUI_W32 && HAVE_SELECT */
 
 #endif /* FEAT_CHANNEL */
--- a/src/gui_w32.c
+++ b/src/gui_w32.c
@@ -553,9 +553,6 @@ typedef BOOL (WINAPI *TGetMonitorInfo)(_
 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 @@ set_tabline_font(void)
     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 ro
     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
--- 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
--- 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;
 }
 
--- a/src/proto/gui_w32.pro
+++ b/src/proto/gui_w32.pro
@@ -96,5 +96,4 @@ void gui_mch_post_balloon(BalloonEval *b
 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 : */
--- a/src/proto/os_mswin.pro
+++ b/src/proto/os_mswin.pro
@@ -50,4 +50,5 @@ char_u *serverGetReply(HWND server, int 
 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 : */
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1195,
+/**/
     1194,
 /**/
     1193,
--- a/src/vim.h
+++ b/src/vim.h
@@ -530,6 +530,8 @@ typedef unsigned long u8char_T;	    /* l
 # ifdef HAVE_SYS_POLL_H
 #  include <sys/poll.h>
 #  define HAVE_POLL
+# elif defined(WIN32) && !defined(FEAT_GUI_W32)
+#  define HAVE_SELECT
 # else
 #  ifdef HAVE_POLL_H
 #   include <poll.h>