@@ -176,11 +176,11 @@ typedef int waitstatus;
176176static pid_t wait4pid (pid_t , waitstatus * );
177177
178178static int WaitForChar (long );
179- static int WaitForCharOrMouse (long );
179+ static int WaitForCharOrMouse (long , int * break_loop );
180180#if defined(__BEOS__ ) || defined(VMS )
181- int RealWaitForChar (int , long , int * );
181+ int RealWaitForChar (int , long , int * , int * break_loop );
182182#else
183- static int RealWaitForChar (int , long , int * );
183+ static int RealWaitForChar (int , long , int * , int * break_loop );
184184#endif
185185
186186#ifdef FEAT_XCLIPBOARD
@@ -366,7 +366,7 @@ mch_write(char_u *s, int len)
366366{
367367 ignored = (int )write (1 , (char * )s , len );
368368 if (p_wd ) /* Unix is too fast, slow down a bit more */
369- RealWaitForChar (read_cmd_fd , p_wd , NULL );
369+ RealWaitForChar (read_cmd_fd , p_wd , NULL , NULL );
370370}
371371
372372/*
@@ -4780,7 +4780,7 @@ mch_call_shell(
47804780 * to some terminal (vt52?).
47814781 */
47824782 ++ noread_cnt ;
4783- while (RealWaitForChar (fromshell_fd , 10L , NULL ))
4783+ while (RealWaitForChar (fromshell_fd , 10L , NULL , NULL ))
47844784 {
47854785 len = read_eintr (fromshell_fd , buffer
47864786# ifdef FEAT_MBYTE
@@ -5365,7 +5365,7 @@ mch_clear_job(job_T *job)
53655365 void
53665366mch_breakcheck (void )
53675367{
5368- if (curr_tmode == TMODE_RAW && RealWaitForChar (read_cmd_fd , 0L , NULL ))
5368+ if (curr_tmode == TMODE_RAW && RealWaitForChar (read_cmd_fd , 0L , NULL , NULL ))
53695369 fill_input_buf (FALSE);
53705370}
53715371
@@ -5382,10 +5382,11 @@ WaitForChar(long msec)
53825382#ifdef FEAT_TIMERS
53835383 long due_time ;
53845384 long remaining = msec ;
5385+ int break_loop = FALSE;
53855386
53865387 /* When waiting very briefly don't trigger timers. */
53875388 if (msec >= 0 && msec < 10L )
5388- return WaitForCharOrMouse (msec );
5389+ return WaitForCharOrMouse (msec , NULL );
53895390
53905391 while (msec < 0 || remaining > 0 )
53915392 {
@@ -5394,14 +5395,18 @@ WaitForChar(long msec)
53945395 due_time = check_due_timer ();
53955396 if (due_time <= 0 || (msec > 0 && due_time > remaining ))
53965397 due_time = remaining ;
5397- if (WaitForCharOrMouse (due_time ))
5398+ if (WaitForCharOrMouse (due_time , & break_loop ))
53985399 return TRUE;
5400+ if (break_loop )
5401+ /* Nothing available, but need to return so that side effects get
5402+ * handled, such as handling a message on a channel. */
5403+ return FALSE;
53995404 if (msec > 0 )
54005405 remaining -= due_time ;
54015406 }
54025407 return FALSE;
54035408#else
5404- return WaitForCharOrMouse (msec );
5409+ return WaitForCharOrMouse (msec , NULL );
54055410#endif
54065411}
54075412
@@ -5412,7 +5417,7 @@ WaitForChar(long msec)
54125417 * When a GUI is being used, this will never get called -- webb
54135418 */
54145419 static int
5415- WaitForCharOrMouse (long msec )
5420+ WaitForCharOrMouse (long msec , int * break_loop )
54165421{
54175422#ifdef FEAT_MOUSE_GPM
54185423 int gpm_process_wanted ;
@@ -5458,9 +5463,10 @@ WaitForCharOrMouse(long msec)
54585463# endif
54595464# ifdef FEAT_MOUSE_GPM
54605465 gpm_process_wanted = 0 ;
5461- avail = RealWaitForChar (read_cmd_fd , msec , & gpm_process_wanted );
5466+ avail = RealWaitForChar (read_cmd_fd , msec ,
5467+ & gpm_process_wanted , break_loop );
54625468# else
5463- avail = RealWaitForChar (read_cmd_fd , msec , NULL );
5469+ avail = RealWaitForChar (read_cmd_fd , msec , NULL , break_loop );
54645470# endif
54655471 if (!avail )
54665472 {
@@ -5479,10 +5485,11 @@ WaitForCharOrMouse(long msec)
54795485# ifdef FEAT_XCLIPBOARD
54805486 || (!avail && rest != 0 )
54815487# endif
5482- );
5488+ )
5489+ ;
54835490
54845491#else
5485- avail = RealWaitForChar (read_cmd_fd , msec , NULL );
5492+ avail = RealWaitForChar (read_cmd_fd , msec , NULL , break_loop );
54865493#endif
54875494 return avail ;
54885495}
@@ -5501,7 +5508,7 @@ WaitForCharOrMouse(long msec)
55015508#else
55025509 static int
55035510#endif
5504- RealWaitForChar (int fd , long msec , int * check_for_gpm UNUSED )
5511+ RealWaitForChar (int fd , long msec , int * check_for_gpm UNUSED , int * break_loop )
55055512{
55065513 int ret ;
55075514 int result ;
@@ -5614,6 +5621,8 @@ RealWaitForChar(int fd, long msec, int *check_for_gpm UNUSED)
56145621 ret = poll (fds , nfd , towait );
56155622
56165623 result = ret > 0 && (fds [0 ].revents & POLLIN );
5624+ if (break_loop != NULL && ret > 0 )
5625+ * break_loop = TRUE;
56175626
56185627# ifdef FEAT_MZSCHEME
56195628 if (ret == 0 && mzquantum_used )
@@ -5745,6 +5754,8 @@ RealWaitForChar(int fd, long msec, int *check_for_gpm UNUSED)
57455754 result = ret > 0 && FD_ISSET (fd , & rfds );
57465755 if (result )
57475756 -- ret ;
5757+ if (break_loop != NULL && ret > 0 )
5758+ * break_loop = TRUE;
57485759
57495760# ifdef EINTR
57505761 if (ret == -1 && errno == EINTR )
0 commit comments