Skip to content

Commit f12d983

Browse files
committed
patch 7.4.1195
Problem: The channel feature does not work in the MS-Windows console. Solution: Add win32 console support. (Yasuhiro Matsumoto)
1 parent 8316246 commit f12d983

File tree

8 files changed

+53
-30
lines changed

8 files changed

+53
-30
lines changed

src/channel.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ typedef struct {
9191
#ifdef FEAT_GUI_GTK
9292
gint ch_inputHandler; /* Cookie for input */
9393
#endif
94-
#ifdef FEAT_GUI_W32
94+
#ifdef WIN32
9595
int ch_inputHandler; /* simply ret.value of WSAAsyncSelect() */
9696
#endif
9797

@@ -279,14 +279,14 @@ channel_open(char *hostname, int port_in, void (*close_cb)(void))
279279
int sd;
280280
struct sockaddr_in server;
281281
struct hostent * host;
282-
#ifdef FEAT_GUI_W32
282+
#ifdef WIN32
283283
u_short port = port_in;
284284
#else
285285
int port = port_in;
286286
#endif
287287
int idx;
288288

289-
#ifdef FEAT_GUI_W32
289+
#ifdef WIN32
290290
channel_init_winsock();
291291
#endif
292292

@@ -861,7 +861,7 @@ channel_read_block(int idx)
861861
return channel_get(idx);
862862
}
863863

864-
# if defined(FEAT_GUI_W32) || defined(PROTO)
864+
# if defined(WIN32) || defined(PROTO)
865865
/*
866866
* Lookup the channel index from the socket.
867867
* Returns -1 when the socket isn't found.
@@ -965,7 +965,7 @@ channel_poll_check(int ret_in, void *fds_in)
965965
}
966966
# endif /* UNIX && !HAVE_SELECT */
967967

968-
# if (defined(UNIX) && defined(HAVE_SELECT)) || defined(PROTO)
968+
# if (!defined(FEAT_GUI_W32) && defined(HAVE_SELECT)) || defined(PROTO)
969969
/*
970970
* The type of "rfds" is hidden to avoid problems with the function proto.
971971
*/
@@ -1007,6 +1007,6 @@ channel_select_check(int ret_in, void *rfds_in)
10071007

10081008
return ret;
10091009
}
1010-
# endif /* UNIX && HAVE_SELECT */
1010+
# endif /* !FEAT_GUI_W32 && HAVE_SELECT */
10111011

10121012
#endif /* FEAT_CHANNEL */

src/gui_w32.c

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,6 @@ typedef BOOL (WINAPI *TGetMonitorInfo)(_HMONITOR, _MONITORINFO *);
553553
static TMonitorFromWindow pMonitorFromWindow = NULL;
554554
static TGetMonitorInfo pGetMonitorInfo = NULL;
555555
static HANDLE user32_lib = NULL;
556-
#ifdef FEAT_CHANNEL
557-
int WSInitialized = FALSE; /* WinSock is initialized */
558-
#endif
559556
/*
560557
* Return TRUE when running under Windows NT 3.x or Win32s, both of which have
561558
* less fancy GUI APIs.
@@ -844,6 +841,7 @@ _OnWindowPosChanged(
844841
const LPWINDOWPOS lpwpos)
845842
{
846843
static int x = 0, y = 0, cx = 0, cy = 0;
844+
extern int WSInitialized;
847845

848846
if (WSInitialized && (lpwpos->x != x || lpwpos->y != y
849847
|| lpwpos->cx != cx || lpwpos->cy != cy))
@@ -5049,22 +5047,3 @@ netbeans_draw_multisign_indicator(int row)
50495047
SetPixel(s_hdc, x+2, y, gui.currFgColor);
50505048
}
50515049
#endif
5052-
5053-
#if defined(FEAT_CHANNEL) || defined(PROTO)
5054-
/*
5055-
* Initialize the Winsock dll.
5056-
*/
5057-
void
5058-
channel_init_winsock()
5059-
{
5060-
WSADATA wsaData;
5061-
int wsaerr;
5062-
5063-
if (WSInitialized)
5064-
return;
5065-
5066-
wsaerr = WSAStartup(MAKEWORD(2, 2), &wsaData);
5067-
if (wsaerr == 0)
5068-
WSInitialized = TRUE;
5069-
}
5070-
#endif

src/os_mswin.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ extern HWND s_hwnd;
161161
static HWND s_hwnd = 0; /* console window handle, set by GetConsoleHwnd() */
162162
#endif
163163

164-
extern int WSInitialized;
164+
#ifdef FEAT_CHANNEL
165+
int WSInitialized = FALSE; /* WinSock is initialized */
166+
#endif
165167

166168
/* Don't generate prototypes here, because some systems do have these
167169
* functions. */
@@ -3093,3 +3095,22 @@ get_logfont(
30933095
}
30943096

30953097
#endif /* defined(FEAT_GUI) || defined(FEAT_PRINTER) */
3098+
3099+
#if defined(FEAT_CHANNEL) || defined(PROTO)
3100+
/*
3101+
* Initialize the Winsock dll.
3102+
*/
3103+
void
3104+
channel_init_winsock()
3105+
{
3106+
WSADATA wsaData;
3107+
int wsaerr;
3108+
3109+
if (WSInitialized)
3110+
return;
3111+
3112+
wsaerr = WSAStartup(MAKEWORD(2, 2), &wsaData);
3113+
if (wsaerr == 0)
3114+
WSInitialized = TRUE;
3115+
}
3116+
#endif

src/os_win32.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,11 @@ WaitForChar(long msec)
14431443
INPUT_RECORD ir;
14441444
DWORD cRecords;
14451445
WCHAR ch, ch2;
1446+
#ifdef FEAT_CHANNEL
1447+
int ret;
1448+
fd_set rfds;
1449+
int maxfd;
1450+
#endif
14461451

14471452
if (msec > 0)
14481453
/* Wait until the specified time has elapsed. */
@@ -1459,9 +1464,22 @@ WaitForChar(long msec)
14591464
#ifdef FEAT_MZSCHEME
14601465
mzvim_check_threads();
14611466
#endif
1467+
14621468
#ifdef FEAT_CLIENTSERVER
14631469
serverProcessPendingMessages();
14641470
#endif
1471+
1472+
#ifdef FEAT_CHANNEL
1473+
FD_ZERO(&rfds);
1474+
maxfd = channel_select_setup(-1, &rfds);
1475+
if (maxfd >= 0)
1476+
{
1477+
ret = select(maxfd + 1, &rfds, NULL, NULL, NULL);
1478+
if (ret > 0 && channel_select_check(ret, &rfds) > 0)
1479+
return TRUE;
1480+
}
1481+
#endif
1482+
14651483
if (0
14661484
#ifdef FEAT_MOUSE
14671485
|| g_nMouseClick != -1
@@ -1562,6 +1580,7 @@ WaitForChar(long msec)
15621580
if (input_available())
15631581
return TRUE;
15641582
#endif
1583+
15651584
return FALSE;
15661585
}
15671586

src/proto/gui_w32.pro

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,4 @@ void gui_mch_post_balloon(BalloonEval *beval, char_u *mesg);
9696
BalloonEval *gui_mch_create_beval_area(void *target, char_u *mesg, void (*mesgCB)(BalloonEval *, int), void *clientData);
9797
void gui_mch_destroy_beval_area(BalloonEval *beval);
9898
void netbeans_draw_multisign_indicator(int row);
99-
void channel_init_winsock(void);
10099
/* vim: set ft=c : */

src/proto/os_mswin.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@ char_u *serverGetReply(HWND server, int *expr_res, int remove, int wait);
5050
void serverProcessPendingMessages(void);
5151
char *charset_id2name(int id);
5252
int get_logfont(LOGFONT *lf, char_u *name, HDC printer_dc, int verbose);
53+
void channel_init_winsock(void);
5354
/* vim: set ft=c : */

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,8 @@ static char *(features[]) =
746746

747747
static int included_patches[] =
748748
{ /* Add new patch number below this line */
749+
/**/
750+
1195,
749751
/**/
750752
1194,
751753
/**/

src/vim.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,8 @@ typedef unsigned long u8char_T; /* long should be 32 bits or more */
530530
# ifdef HAVE_SYS_POLL_H
531531
# include <sys/poll.h>
532532
# define HAVE_POLL
533+
# elif defined(WIN32) && !defined(FEAT_GUI_W32)
534+
# define HAVE_SELECT
533535
# else
534536
# ifdef HAVE_POLL_H
535537
# include <poll.h>

0 commit comments

Comments
 (0)