Skip to content

Commit ed5a78e

Browse files
committed
patch 7.4.1355
Problem: Win32 console and GUI handle channels differently. Solution: Consolidate code between Win32 console and GUI.
1 parent 223b723 commit ed5a78e

File tree

6 files changed

+79
-69
lines changed

6 files changed

+79
-69
lines changed

src/channel.c

Lines changed: 69 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,17 +1508,11 @@ channel_free_all(void)
15081508
static int
15091509
channel_wait(channel_T *channel, sock_T fd, int timeout)
15101510
{
1511-
#if defined(HAVE_SELECT) && !defined(FEAT_GUI_W32)
1512-
struct timeval tval;
1513-
fd_set rfds;
1514-
int ret;
1515-
15161511
if (timeout > 0)
15171512
ch_logn(channel, "Waiting for up to %d msec", timeout);
15181513

1519-
15201514
# ifdef WIN32
1521-
if (channel->CH_SOCK == CHAN_FD_INVALID)
1515+
if (fd != channel->CH_SOCK)
15221516
{
15231517
DWORD nread;
15241518
int diff;
@@ -1537,44 +1531,48 @@ channel_wait(channel_T *channel, sock_T fd, int timeout)
15371531
* TODO: increase the sleep time when looping more often */
15381532
Sleep(5);
15391533
}
1540-
return FAIL;
15411534
}
1535+
else
15421536
#endif
1543-
1544-
FD_ZERO(&rfds);
1545-
FD_SET((int)fd, &rfds);
1546-
tval.tv_sec = timeout / 1000;
1547-
tval.tv_usec = (timeout % 1000) * 1000;
1548-
for (;;)
15491537
{
1550-
ret = select((int)fd + 1, &rfds, NULL, NULL, &tval);
1551-
# ifdef EINTR
1552-
if (ret == -1 && errno == EINTR)
1553-
continue;
1554-
# endif
1555-
if (ret <= 0)
1538+
#if defined(FEAT_GUI_W32)
1539+
/* Can't check socket for Win32 GUI, always return OK. */
1540+
ch_log(channel, "Can't check, assuming there is something to read");
1541+
return OK;
1542+
#else
1543+
# if defined(HAVE_SELECT)
1544+
struct timeval tval;
1545+
fd_set rfds;
1546+
int ret;
1547+
1548+
FD_ZERO(&rfds);
1549+
FD_SET((int)fd, &rfds);
1550+
tval.tv_sec = timeout / 1000;
1551+
tval.tv_usec = (timeout % 1000) * 1000;
1552+
for (;;)
15561553
{
1557-
ch_log(channel, "Nothing to read");
1558-
return FAIL;
1554+
ret = select((int)fd + 1, &rfds, NULL, NULL, &tval);
1555+
# ifdef EINTR
1556+
SOCK_ERRNO;
1557+
if (ret == -1 && errno == EINTR)
1558+
continue;
1559+
# endif
1560+
if (ret > 0)
1561+
return OK;
1562+
break;
15591563
}
1560-
break;
1561-
}
1562-
#else
1563-
# ifdef HAVE_POLL
1564-
struct pollfd fds;
1564+
# else
1565+
struct pollfd fds;
15651566

1566-
if (timeout > 0)
1567-
ch_logn(channel, "Waiting for %d msec", timeout);
1568-
fds.fd = fd;
1569-
fds.events = POLLIN;
1570-
if (poll(&fds, 1, timeout) <= 0)
1571-
{
1572-
ch_log(channel, "Nothing to read");
1573-
return FAIL;
1574-
}
1567+
fds.fd = fd;
1568+
fds.events = POLLIN;
1569+
if (poll(&fds, 1, timeout) > 0)
1570+
return OK;
15751571
# endif
15761572
#endif
1577-
return OK;
1573+
}
1574+
ch_log(channel, "Nothing to read");
1575+
return FAIL;
15781576
}
15791577

15801578
/*
@@ -1667,8 +1665,9 @@ channel_read(channel_T *channel, int which, char *func)
16671665
}
16681666
#endif
16691667

1670-
/* Reading a socket disconnection (readlen == 0), or a socket error. */
1671-
if (readlen <= 0)
1668+
/* Reading a socket disconnection (readlen == 0), or a socket error.
1669+
* TODO: call error callback. */
1670+
if (readlen <= 0 && channel->ch_job == NULL)
16721671
{
16731672
/* Queue a "DETACH" netbeans message in the command queue in order to
16741673
* terminate the netbeans session later. Do not end the session here
@@ -1836,6 +1835,35 @@ channel_fd2channel(sock_T fd, int *whichp)
18361835
}
18371836
return NULL;
18381837
}
1838+
1839+
void
1840+
channel_handle_events(void)
1841+
{
1842+
channel_T *channel;
1843+
int which;
1844+
static int loop = 0;
1845+
1846+
/* Skip heavily polling */
1847+
if (loop++ % 2)
1848+
return;
1849+
1850+
for (channel = first_channel; channel != NULL; channel = channel->ch_next)
1851+
{
1852+
# ifdef FEAT_GUI_W32
1853+
/* only check the pipes */
1854+
for (which = CHAN_OUT; which < CHAN_ERR; ++which)
1855+
# else
1856+
# ifdef CHANNEL_PIPES
1857+
/* check the socket and pipes */
1858+
for (which = CHAN_SOCK; which < CHAN_ERR; ++which)
1859+
# else
1860+
/* only check the socket */
1861+
which = CHAN_SOCK;
1862+
# endif
1863+
# endif
1864+
channel_read(channel, which, "channel_handle_events");
1865+
}
1866+
}
18391867
# endif
18401868

18411869
/*
@@ -1969,7 +1997,7 @@ channel_poll_check(int ret_in, void *fds_in)
19691997
}
19701998
# endif /* UNIX && !HAVE_SELECT */
19711999

1972-
# if (!defined(FEAT_GUI_W32) && defined(HAVE_SELECT)) || defined(PROTO)
2000+
# if (!defined(WIN32) && defined(HAVE_SELECT)) || defined(PROTO)
19732001
/*
19742002
* The type of "rfds" is hidden to avoid problems with the function proto.
19752003
*/
@@ -2034,7 +2062,7 @@ channel_select_check(int ret_in, void *rfds_in)
20342062

20352063
return ret;
20362064
}
2037-
# endif /* !FEAT_GUI_W32 && HAVE_SELECT */
2065+
# endif /* !WIN32 && HAVE_SELECT */
20382066

20392067
/*
20402068
* Execute queued up commands.

src/eval.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14635,14 +14635,14 @@ f_job_start(typval_T *argvars UNUSED, typval_T *rettv)
1463514635
ga_concat(&ga, (char_u *)" ");
1463614636
ga_concat(&ga, (char_u *)argv[i]);
1463714637
}
14638-
ch_logs(NULL, "Starting job: %s", ga.ga_data);
14638+
ch_logs(NULL, "Starting job: %s", (char *)ga.ga_data);
1463914639
ga_clear(&ga);
1464014640
}
1464114641
# endif
1464214642
mch_start_job(argv, job, &options);
1464314643
#else
1464414644
# ifdef FEAT_CHANNEL
14645-
ch_logs(NULL, "Starting job: %s", cmd);
14645+
ch_logs(NULL, "Starting job: %s", (char *)cmd);
1464614646
# endif
1464714647
mch_start_job((char *)cmd, job, &options);
1464814648
#endif

src/gui_w48.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,6 +2099,10 @@ gui_mch_wait_for_chars(int wtime)
20992099
parse_queued_messages();
21002100
#endif
21012101

2102+
#ifdef FEAT_CHANNEL
2103+
channel_handle_events();
2104+
#endif
2105+
21022106
/*
21032107
* Don't use gui_mch_update() because then we will spin-lock until a
21042108
* char arrives, instead we use GetMessage() to hang until an

src/os_win32.c

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,30 +1128,6 @@ mch_setmouse(int on)
11281128
SetConsoleMode(g_hConIn, cmodein);
11291129
}
11301130

1131-
#ifdef FEAT_CHANNEL
1132-
static int
1133-
handle_channel_event(void)
1134-
{
1135-
int ret;
1136-
fd_set rfds;
1137-
int maxfd;
1138-
1139-
FD_ZERO(&rfds);
1140-
maxfd = channel_select_setup(-1, &rfds);
1141-
if (maxfd >= 0)
1142-
{
1143-
struct timeval tv;
1144-
1145-
tv.tv_sec = 0;
1146-
tv.tv_usec = 0;
1147-
ret = select(maxfd + 1, &rfds, NULL, NULL, &tv);
1148-
if (ret > 0 && channel_select_check(ret, &rfds) > 0)
1149-
return TRUE;
1150-
}
1151-
return FALSE;
1152-
}
1153-
#endif
1154-
11551131
/*
11561132
* Decode a MOUSE_EVENT. If it's a valid event, return MOUSE_LEFT,
11571133
* MOUSE_MIDDLE, or MOUSE_RIGHT for a click; MOUSE_DRAG for a mouse
@@ -1495,8 +1471,7 @@ WaitForChar(long msec)
14951471
#endif
14961472

14971473
#ifdef FEAT_CHANNEL
1498-
if (handle_channel_event())
1499-
return TRUE;
1474+
channel_handle_events();
15001475
#endif
15011476

15021477
if (0

src/proto/channel.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ void channel_read(channel_T *channel, int which, char *func);
3030
char_u *channel_read_block(channel_T *channel);
3131
int channel_read_json_block(channel_T *channel, int id, typval_T **rettv);
3232
channel_T *channel_fd2channel(sock_T fd, int *whichp);
33+
void channel_handle_events(void);
3334
int channel_send(channel_T *channel, char_u *buf, char *fun);
3435
int channel_poll_setup(int nfd_in, void *fds_in);
3536
int channel_poll_check(int ret_in, void *fds_in);

src/version.c

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

748748
static int included_patches[] =
749749
{ /* Add new patch number below this line */
750+
/**/
751+
1355,
750752
/**/
751753
1354,
752754
/**/

0 commit comments

Comments
 (0)