@@ -557,12 +557,11 @@ channel_open(char *hostname, int port_in, int waittime, void (*close_cb)(void))
557
557
}
558
558
memcpy ((char * )& server .sin_addr , host -> h_addr , host -> h_length );
559
559
560
- #if defined( __APPLE__ ) && __APPLE__ == 1
561
- /* On Mac a zero timeout almost never works. At least wait one
562
- * millisecond . */
560
+ /* On Mac and Solaris a zero timeout almost never works. At least wait
561
+ * one millisecond. Let's do it for all systems, because we don't know why
562
+ * this is needed . */
563
563
if (waittime == 0 )
564
564
waittime = 1 ;
565
- #endif
566
565
567
566
/*
568
567
* For Unix we need to call connect() again after connect() failed.
@@ -767,44 +766,25 @@ channel_set_job(channel_T *channel, job_T *job)
767
766
channel -> ch_job = job ;
768
767
}
769
768
770
- /*
771
- * Set the mode of channel "channel" to "mode".
772
- */
773
- void
774
- channel_set_mode (channel_T * channel , ch_mode_T mode )
775
- {
776
- channel -> ch_mode = mode ;
777
- }
778
-
779
- /*
780
- * Set the read timeout of channel "channel".
781
- */
782
- void
783
- channel_set_timeout (channel_T * channel , int timeout )
784
- {
785
- channel -> ch_timeout = timeout ;
786
- }
787
-
788
- /*
789
- * Set the callback for channel "channel".
790
- */
791
- void
792
- channel_set_callback (channel_T * channel , char_u * callback )
793
- {
794
- vim_free (channel -> ch_callback );
795
- channel -> ch_callback = vim_strsave (callback );
796
- }
797
-
798
769
/*
799
770
* Set various properties from an "options" argument.
800
771
*/
801
772
void
802
773
channel_set_options (channel_T * channel , jobopt_T * options )
803
774
{
804
- channel_set_mode (channel , options -> jo_mode );
775
+ if (options -> jo_set & JO_MODE )
776
+ channel -> ch_mode = options -> jo_mode ;
777
+ if (options -> jo_set & JO_TIMEOUT )
778
+ channel -> ch_timeout = options -> jo_timeout ;
805
779
806
- if (options -> jo_callback != NULL && * options -> jo_callback != NUL )
807
- channel_set_callback (channel , options -> jo_callback );
780
+ if (options -> jo_set & JO_CALLBACK )
781
+ {
782
+ vim_free (channel -> ch_callback );
783
+ if (options -> jo_callback != NULL && * options -> jo_callback != NUL )
784
+ channel -> ch_callback = vim_strsave (options -> jo_callback );
785
+ else
786
+ channel -> ch_callback = NULL ;
787
+ }
808
788
}
809
789
810
790
/*
@@ -1527,17 +1507,11 @@ channel_free_all(void)
1527
1507
static int
1528
1508
channel_wait (channel_T * channel , sock_T fd , int timeout )
1529
1509
{
1530
- #if defined(HAVE_SELECT ) && !defined(FEAT_GUI_W32 )
1531
- struct timeval tval ;
1532
- fd_set rfds ;
1533
- int ret ;
1534
-
1535
1510
if (timeout > 0 )
1536
1511
ch_logn (channel , "Waiting for up to %d msec" , timeout );
1537
1512
1538
-
1539
1513
# ifdef WIN32
1540
- if (channel -> CH_SOCK == CHAN_FD_INVALID )
1514
+ if (fd != channel -> CH_SOCK )
1541
1515
{
1542
1516
DWORD nread ;
1543
1517
int diff ;
@@ -1556,44 +1530,48 @@ channel_wait(channel_T *channel, sock_T fd, int timeout)
1556
1530
* TODO: increase the sleep time when looping more often */
1557
1531
Sleep (5 );
1558
1532
}
1559
- return FAIL ;
1560
1533
}
1534
+ else
1561
1535
#endif
1562
-
1563
- FD_ZERO (& rfds );
1564
- FD_SET ((int )fd , & rfds );
1565
- tval .tv_sec = timeout / 1000 ;
1566
- tval .tv_usec = (timeout % 1000 ) * 1000 ;
1567
- for (;;)
1568
1536
{
1569
- ret = select ((int )fd + 1 , & rfds , NULL , NULL , & tval );
1570
- # ifdef EINTR
1571
- if (ret == -1 && errno == EINTR )
1572
- continue ;
1573
- # endif
1574
- if (ret <= 0 )
1537
+ #if defined(FEAT_GUI_W32 )
1538
+ /* Can't check socket for Win32 GUI, always return OK. */
1539
+ ch_log (channel , "Can't check, assuming there is something to read" );
1540
+ return OK ;
1541
+ #else
1542
+ # if defined(HAVE_SELECT )
1543
+ struct timeval tval ;
1544
+ fd_set rfds ;
1545
+ int ret ;
1546
+
1547
+ FD_ZERO (& rfds );
1548
+ FD_SET ((int )fd , & rfds );
1549
+ tval .tv_sec = timeout / 1000 ;
1550
+ tval .tv_usec = (timeout % 1000 ) * 1000 ;
1551
+ for (;;)
1575
1552
{
1576
- ch_log (channel , "Nothing to read" );
1577
- return FAIL ;
1553
+ ret = select ((int )fd + 1 , & rfds , NULL , NULL , & tval );
1554
+ # ifdef EINTR
1555
+ SOCK_ERRNO ;
1556
+ if (ret == -1 && errno == EINTR )
1557
+ continue ;
1558
+ # endif
1559
+ if (ret > 0 )
1560
+ return OK ;
1561
+ break ;
1578
1562
}
1579
- break ;
1580
- }
1581
- #else
1582
- # ifdef HAVE_POLL
1583
- struct pollfd fds ;
1563
+ # else
1564
+ struct pollfd fds ;
1584
1565
1585
- if (timeout > 0 )
1586
- ch_logn (channel , "Waiting for %d msec" , timeout );
1587
- fds .fd = fd ;
1588
- fds .events = POLLIN ;
1589
- if (poll (& fds , 1 , timeout ) <= 0 )
1590
- {
1591
- ch_log (channel , "Nothing to read" );
1592
- return FAIL ;
1593
- }
1566
+ fds .fd = fd ;
1567
+ fds .events = POLLIN ;
1568
+ if (poll (& fds , 1 , timeout ) > 0 )
1569
+ return OK ;
1594
1570
# endif
1595
1571
#endif
1596
- return OK ;
1572
+ }
1573
+ ch_log (channel , "Nothing to read" );
1574
+ return FAIL ;
1597
1575
}
1598
1576
1599
1577
/*
@@ -1686,8 +1664,9 @@ channel_read(channel_T *channel, int which, char *func)
1686
1664
}
1687
1665
#endif
1688
1666
1689
- /* Reading a socket disconnection (readlen == 0), or a socket error. */
1690
- if (readlen <= 0 )
1667
+ /* Reading a socket disconnection (readlen == 0), or a socket error.
1668
+ * TODO: call error callback. */
1669
+ if (readlen <= 0 && channel -> ch_job == NULL )
1691
1670
{
1692
1671
/* Queue a "DETACH" netbeans message in the command queue in order to
1693
1672
* terminate the netbeans session later. Do not end the session here
@@ -1855,6 +1834,35 @@ channel_fd2channel(sock_T fd, int *whichp)
1855
1834
}
1856
1835
return NULL ;
1857
1836
}
1837
+
1838
+ void
1839
+ channel_handle_events (void )
1840
+ {
1841
+ channel_T * channel ;
1842
+ int which ;
1843
+ static int loop = 0 ;
1844
+
1845
+ /* Skip heavily polling */
1846
+ if (loop ++ % 2 )
1847
+ return ;
1848
+
1849
+ for (channel = first_channel ; channel != NULL ; channel = channel -> ch_next )
1850
+ {
1851
+ # ifdef FEAT_GUI_W32
1852
+ /* only check the pipes */
1853
+ for (which = CHAN_OUT ; which < CHAN_ERR ; ++ which )
1854
+ # else
1855
+ # ifdef CHANNEL_PIPES
1856
+ /* check the socket and pipes */
1857
+ for (which = CHAN_SOCK ; which < CHAN_ERR ; ++ which )
1858
+ # else
1859
+ /* only check the socket */
1860
+ which = CHAN_SOCK ;
1861
+ # endif
1862
+ # endif
1863
+ channel_read (channel , which , "channel_handle_events" );
1864
+ }
1865
+ }
1858
1866
# endif
1859
1867
1860
1868
/*
@@ -1988,7 +1996,7 @@ channel_poll_check(int ret_in, void *fds_in)
1988
1996
}
1989
1997
# endif /* UNIX && !HAVE_SELECT */
1990
1998
1991
- # if (!defined(FEAT_GUI_W32 ) && defined(HAVE_SELECT )) || defined(PROTO )
1999
+ # if (!defined(WIN32 ) && defined(HAVE_SELECT )) || defined(PROTO )
1992
2000
/*
1993
2001
* The type of "rfds" is hidden to avoid problems with the function proto.
1994
2002
*/
@@ -2053,7 +2061,7 @@ channel_select_check(int ret_in, void *rfds_in)
2053
2061
2054
2062
return ret ;
2055
2063
}
2056
- # endif /* !FEAT_GUI_W32 && HAVE_SELECT */
2064
+ # endif /* !WIN32 && HAVE_SELECT */
2057
2065
2058
2066
/*
2059
2067
* Execute queued up commands.
0 commit comments