@@ -1508,17 +1508,11 @@ channel_free_all(void)
15081508 static int
15091509channel_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.
0 commit comments