]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 7.4.1355 v7.4.1355
authorBram Moolenaar <Bram@vim.org>
Fri, 19 Feb 2016 20:05:03 +0000 (21:05 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 19 Feb 2016 20:05:03 +0000 (21:05 +0100)
Problem:    Win32 console and GUI handle channels differently.
Solution:   Consolidate code between Win32 console and GUI.

src/channel.c
src/eval.c
src/gui_w48.c
src/os_win32.c
src/proto/channel.pro
src/version.c

index 49fa8f9cc183f90620cc4ac93d8e7089c904d698..561a9e5f1feb9e73bc36a7c0f91baa939d1ca29a 100644 (file)
@@ -1508,17 +1508,11 @@ channel_free_all(void)
     static int
 channel_wait(channel_T *channel, sock_T fd, int timeout)
 {
-#if defined(HAVE_SELECT) && !defined(FEAT_GUI_W32)
-    struct timeval     tval;
-    fd_set             rfds;
-    int                        ret;
-
     if (timeout > 0)
        ch_logn(channel, "Waiting for up to %d msec", timeout);
 
-
 # ifdef WIN32
-    if (channel->CH_SOCK == CHAN_FD_INVALID)
+    if (fd != channel->CH_SOCK)
     {
        DWORD   nread;
        int     diff;
@@ -1537,44 +1531,48 @@ channel_wait(channel_T *channel, sock_T fd, int timeout)
             * TODO: increase the sleep time when looping more often */
            Sleep(5);
        }
-       return FAIL;
     }
+    else
 #endif
-
-    FD_ZERO(&rfds);
-    FD_SET((int)fd, &rfds);
-    tval.tv_sec = timeout / 1000;
-    tval.tv_usec = (timeout % 1000) * 1000;
-    for (;;)
     {
-       ret = select((int)fd + 1, &rfds, NULL, NULL, &tval);
-# ifdef EINTR
-       if (ret == -1 && errno == EINTR)
-           continue;
-# endif
-       if (ret <= 0)
+#if defined(FEAT_GUI_W32)
+       /* Can't check socket for Win32 GUI, always return OK. */
+       ch_log(channel, "Can't check, assuming there is something to read");
+       return OK;
+#else
+# if defined(HAVE_SELECT)
+       struct timeval  tval;
+       fd_set          rfds;
+       int                     ret;
+
+       FD_ZERO(&rfds);
+       FD_SET((int)fd, &rfds);
+       tval.tv_sec = timeout / 1000;
+       tval.tv_usec = (timeout % 1000) * 1000;
+       for (;;)
        {
-           ch_log(channel, "Nothing to read");
-           return FAIL;
+           ret = select((int)fd + 1, &rfds, NULL, NULL, &tval);
+#  ifdef EINTR
+           SOCK_ERRNO;
+           if (ret == -1 && errno == EINTR)
+               continue;
+#  endif
+           if (ret > 0)
+               return OK;
+           break;
        }
-       break;
-    }
-#else
-# ifdef HAVE_POLL
-    struct pollfd      fds;
+# else
+       struct pollfd   fds;
 
-    if (timeout > 0)
-       ch_logn(channel, "Waiting for %d msec", timeout);
-    fds.fd = fd;
-    fds.events = POLLIN;
-    if (poll(&fds, 1, timeout) <= 0)
-    {
-       ch_log(channel, "Nothing to read");
-       return FAIL;
-    }
+       fds.fd = fd;
+       fds.events = POLLIN;
+       if (poll(&fds, 1, timeout) > 0)
+           return OK;
 # endif
 #endif
-    return OK;
+    }
+    ch_log(channel, "Nothing to read");
+    return FAIL;
 }
 
 /*
@@ -1667,8 +1665,9 @@ channel_read(channel_T *channel, int which, char *func)
     }
 #endif
 
-    /* Reading a socket disconnection (readlen == 0), or a socket error. */
-    if (readlen <= 0)
+    /* Reading a socket disconnection (readlen == 0), or a socket error.
+     * TODO: call error callback. */
+    if (readlen <= 0 && channel->ch_job == NULL)
     {
        /* Queue a "DETACH" netbeans message in the command queue in order to
         * terminate the netbeans session later. Do not end the session here
@@ -1836,6 +1835,35 @@ channel_fd2channel(sock_T fd, int *whichp)
        }
     return NULL;
 }
+
+    void
+channel_handle_events(void)
+{
+    channel_T  *channel;
+    int                which;
+    static int loop = 0;
+
+    /* Skip heavily polling */
+    if (loop++ % 2)
+       return;
+
+    for (channel = first_channel; channel != NULL; channel = channel->ch_next)
+    {
+#  ifdef FEAT_GUI_W32
+       /* only check the pipes */
+       for (which = CHAN_OUT; which < CHAN_ERR; ++which)
+#  else
+#   ifdef CHANNEL_PIPES
+       /* check the socket and pipes */
+       for (which = CHAN_SOCK; which < CHAN_ERR; ++which)
+#   else
+       /* only check the socket */
+       which = CHAN_SOCK;
+#   endif
+#  endif
+       channel_read(channel, which, "channel_handle_events");
+    }
+}
 # endif
 
 /*
@@ -1969,7 +1997,7 @@ channel_poll_check(int ret_in, void *fds_in)
 }
 # endif /* UNIX && !HAVE_SELECT */
 
-# if (!defined(FEAT_GUI_W32) && defined(HAVE_SELECT)) || defined(PROTO)
+# if (!defined(WIN32) && defined(HAVE_SELECT)) || defined(PROTO)
 /*
  * The type of "rfds" is hidden to avoid problems with the function proto.
  */
@@ -2034,7 +2062,7 @@ channel_select_check(int ret_in, void *rfds_in)
 
     return ret;
 }
-# endif /* !FEAT_GUI_W32 && HAVE_SELECT */
+# endif /* !WIN32 && HAVE_SELECT */
 
 /*
  * Execute queued up commands.
index 86ff5855c9f97caad59918da465a60742a2d54b8..781cd3d0e3a4ceef85c05cff434da231885d68ff 100644 (file)
@@ -14635,14 +14635,14 @@ f_job_start(typval_T *argvars UNUSED, typval_T *rettv)
                ga_concat(&ga, (char_u *)"  ");
            ga_concat(&ga, (char_u *)argv[i]);
        }
-       ch_logs(NULL, "Starting job: %s", ga.ga_data);
+       ch_logs(NULL, "Starting job: %s", (char *)ga.ga_data);
        ga_clear(&ga);
     }
 # endif
     mch_start_job(argv, job, &options);
 #else
 # ifdef FEAT_CHANNEL
-    ch_logs(NULL, "Starting job: %s", cmd);
+    ch_logs(NULL, "Starting job: %s", (char *)cmd);
 # endif
     mch_start_job((char *)cmd, job, &options);
 #endif
index 7c08dec76c67ebb7398cbd5ab6f5d2dfc5c474b5..4b755bd8fd3d551bda183ba92a17d32a35013c05 100644 (file)
@@ -2099,6 +2099,10 @@ gui_mch_wait_for_chars(int wtime)
        parse_queued_messages();
 #endif
 
+#ifdef FEAT_CHANNEL
+       channel_handle_events();
+#endif
+
        /*
         * Don't use gui_mch_update() because then we will spin-lock until a
         * char arrives, instead we use GetMessage() to hang until an
index 63d7d60cb5a5126f68bcda3eb719b20a3c8ea766..ae1f0d8afc198cdb4924236c23298dbef862333d 100644 (file)
@@ -1128,30 +1128,6 @@ mch_setmouse(int on)
     SetConsoleMode(g_hConIn, cmodein);
 }
 
-#ifdef FEAT_CHANNEL
-    static int
-handle_channel_event(void)
-{
-    int                    ret;
-    fd_set         rfds;
-    int                    maxfd;
-
-    FD_ZERO(&rfds);
-    maxfd = channel_select_setup(-1, &rfds);
-    if (maxfd >= 0)
-    {
-       struct timeval  tv;
-
-       tv.tv_sec = 0;
-       tv.tv_usec = 0;
-       ret = select(maxfd + 1, &rfds, NULL, NULL, &tv);
-       if (ret > 0 && channel_select_check(ret, &rfds) > 0)
-           return TRUE;
-    }
-    return FALSE;
-}
-#endif
-
 /*
  * Decode a MOUSE_EVENT.  If it's a valid event, return MOUSE_LEFT,
  * MOUSE_MIDDLE, or MOUSE_RIGHT for a click; MOUSE_DRAG for a mouse
@@ -1495,8 +1471,7 @@ WaitForChar(long msec)
 #endif
 
 #ifdef FEAT_CHANNEL
-       if (handle_channel_event())
-           return TRUE;
+       channel_handle_events();
 #endif
 
        if (0
index 265fe0519767b588b0041bc261ebfb2279d82e94..8f92933001c79c1f054e311dc3d3d8a69f84ff6a 100644 (file)
@@ -30,6 +30,7 @@ void channel_read(channel_T *channel, int which, char *func);
 char_u *channel_read_block(channel_T *channel);
 int channel_read_json_block(channel_T *channel, int id, typval_T **rettv);
 channel_T *channel_fd2channel(sock_T fd, int *whichp);
+void channel_handle_events(void);
 int channel_send(channel_T *channel, char_u *buf, char *fun);
 int channel_poll_setup(int nfd_in, void *fds_in);
 int channel_poll_check(int ret_in, void *fds_in);
index 33824d1036d36d6a7ce999b6943e1b492b4a59f6..84bcb349af283b5c068ef52558023f2a80909329 100644 (file)
@@ -747,6 +747,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1355,
 /**/
     1354,
 /**/