Confirm channel is readable in event handler

This commit is contained in:
ichizok
2017-10-18 02:15:24 +09:00
parent 5c8c040a4f
commit f113a44867
3 changed files with 18 additions and 10 deletions
+1 -1
View File
@@ -2301,7 +2301,7 @@ gui_macvim_add_channel(channel_T *channel, ch_part_T part)
0,
dispatch_get_main_queue());
dispatch_source_set_event_handler(s, ^{
channel_read(channel, part, "gui_macvim_add_channel");
channel_may_read(channel, part, "gui_macvim_add_channel");
});
dispatch_resume(s);
return s;
+16 -6
View File
@@ -54,9 +54,7 @@
# define fd_close(sd) close(sd)
#endif
#ifndef FEAT_GUI_MACVIM
static void channel_read(channel_T *channel, ch_part_T part, char *func);
#endif
/* Whether a redraw is needed for appending a line to a buffer. */
static int channel_need_redraw = FALSE;
@@ -3271,11 +3269,7 @@ channel_close_now(channel_T *channel)
* "part" is PART_SOCK, PART_OUT or PART_ERR.
* The data is put in the read queue. No callbacks are invoked here.
*/
#ifndef FEAT_GUI_MACVIM
static void
#else
void
#endif
channel_read(channel_T *channel, ch_part_T part, char *func)
{
static char_u *buf = NULL;
@@ -3561,6 +3555,22 @@ theend:
free_job_options(&opt);
}
# ifdef FEAT_GUI_MACVIM
/*
* Read from channel "channel" in dispatch event handler.
* Channel may be already read out elsewhere before the handler invoked
* after an event arrived, so should be checked again.
*/
void
channel_may_read(channel_T *channel, ch_part_T part, char *func)
{
sock_T fd = channel->ch_part[part].ch_fd;
if (fd != INVALID_FD && channel_wait(channel, fd, 0) == CW_READY)
channel_read(channel, part, func);
}
# endif
# if defined(WIN32) || defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) \
|| defined(PROTO)
/*
+1 -3
View File
@@ -33,6 +33,7 @@ void channel_clear(channel_T *channel);
void channel_free_all(void);
char_u *channel_read_block(channel_T *channel, ch_part_T part, int timeout);
void common_channel_read(typval_T *argvars, typval_T *rettv, int raw);
void channel_may_read(channel_T *channel, ch_part_T part, char *func);
channel_T *channel_fd2channel(sock_T fd, ch_part_T *partp);
void channel_handle_events(int only_keep_open);
int channel_any_keep_open(void);
@@ -71,7 +72,4 @@ job_T *job_start(typval_T *argvars, jobopt_T *opt_arg);
char *job_status(job_T *job);
void job_info(job_T *job, dict_T *dict);
int job_stop(job_T *job, typval_T *argvars, char *type);
#ifdef FEAT_GUI_MACVIM
void channel_read(channel_T *channel, ch_part_T part, char *func);
#endif
/* vim: set ft=c : */