diff src/channel.c @ 14675:71c17b688bc6 v8.1.0350

patch 8.1.0350: Vim may block on ch_sendraw() commit https://github.com/vim/vim/commit/0b1468884a2a1c5d3442cbb7119330e307f0aa3d Author: Bram Moolenaar <Bram@vim.org> Date: Thu Sep 6 16:27:24 2018 +0200 patch 8.1.0350: Vim may block on ch_sendraw() Problem: Vim may block on ch_sendraw() when the job is sending data back to Vim, which isn't read yet. (Nate Bosch) Solution: Add the "noblock" option to job_start(). (closes #2548)
author Christian Brabandt <cb@256bit.org>
date Thu, 06 Sep 2018 16:30:06 +0200
parents 2661d77e440e
children 193471015e1a
line wrap: on
line diff
--- a/src/channel.c
+++ b/src/channel.c
@@ -1180,6 +1180,7 @@ channel_set_options(channel_T *channel, 
 	channel->ch_part[PART_OUT].ch_mode = opt->jo_out_mode;
     if (opt->jo_set & JO_ERR_MODE)
 	channel->ch_part[PART_ERR].ch_mode = opt->jo_err_mode;
+    channel->ch_nonblock = opt->jo_noblock;
 
     if (opt->jo_set & JO_TIMEOUT)
 	for (part = PART_SOCK; part < PART_COUNT; ++part)
@@ -3677,7 +3678,7 @@ channel_any_keep_open()
 channel_set_nonblock(channel_T *channel, ch_part_T part)
 {
     chanpart_T *ch_part = &channel->ch_part[part];
-    int fd = ch_part->ch_fd;
+    int		fd = ch_part->ch_fd;
 
     if (fd != INVALID_FD)
     {
@@ -3722,6 +3723,9 @@ channel_send(
 	return FAIL;
     }
 
+    if (channel->ch_nonblock && !ch_part->ch_nonblocking)
+	channel_set_nonblock(channel, part);
+
     if (ch_log_active())
     {
 	ch_log_lead("SEND ", channel, part);
@@ -4553,6 +4557,12 @@ get_job_options(typval_T *tv, jobopt_T *
 								      == FAIL)
 		    return FAIL;
 	    }
+	    else if (STRCMP(hi->hi_key, "noblock") == 0)
+	    {
+		if (!(supported & JO_MODE))
+		    break;
+		opt->jo_noblock = get_tv_number(item);
+	    }
 	    else if (STRCMP(hi->hi_key, "in_io") == 0
 		    || STRCMP(hi->hi_key, "out_io") == 0
 		    || STRCMP(hi->hi_key, "err_io") == 0)