Skip to content

Instantly share code, notes, and snippets.

@mattn
Created November 28, 2017 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattn/270362fa9a72dff143832ea0d150fc6f to your computer and use it in GitHub Desktop.
Save mattn/270362fa9a72dff143832ea0d150fc6f to your computer and use it in GitHub Desktop.
diff --git a/src/channel.c b/src/channel.c
index 8fc705058..52e8f5f67 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -3316,8 +3316,8 @@ channel_read(channel_T *channel, ch_part_T part, char *func)
* Returns what was read in allocated memory.
* Returns NULL in case of error or timeout.
*/
- char_u *
-channel_read_block(channel_T *channel, ch_part_T part, int timeout)
+ static char_u *
+channel_read_block(channel_T *channel, ch_part_T part, int timeout, int raw)
{
char_u *buf;
char_u *msg;
@@ -3327,14 +3327,14 @@ channel_read_block(channel_T *channel, ch_part_T part, int timeout)
readq_T *node;
ch_log(channel, "Blocking %s read, timeout: %d msec",
- mode == MODE_RAW ? "RAW" : "NL", timeout);
+ (raw || mode == MODE_RAW) ? "RAW" : "NL", timeout);
while (TRUE)
{
node = channel_peek(channel, part);
if (node != NULL)
{
- if (mode == MODE_RAW || (mode == MODE_NL
+ if (raw || mode == MODE_RAW || (mode == MODE_NL
&& channel_first_nl(node) != NULL))
/* got a complete message */
break;
@@ -3354,7 +3354,7 @@ channel_read_block(channel_T *channel, ch_part_T part, int timeout)
}
/* We have a complete message now. */
- if (mode == MODE_RAW)
+ if (raw || mode == MODE_RAW)
{
msg = channel_get_all(channel, part);
}
@@ -3513,7 +3513,8 @@ common_channel_read(typval_T *argvars, typval_T *rettv, int raw)
timeout = opt.jo_timeout;
if (raw || mode == MODE_RAW || mode == MODE_NL)
- rettv->vval.v_string = channel_read_block(channel, part, timeout);
+ rettv->vval.v_string = channel_read_block(channel, part,
+ timeout, raw);
else
{
if (opt.jo_set & JO_ID)
@@ -3955,7 +3956,8 @@ ch_raw_common(typval_T *argvars, typval_T *rettv, int eval)
timeout = opt.jo_timeout;
else
timeout = channel_get_timeout(channel, part_read);
- rettv->vval.v_string = channel_read_block(channel, part_read, timeout);
+ rettv->vval.v_string = channel_read_block(channel, part_read,
+ timeout, TRUE);
}
free_job_options(&opt);
}
diff --git a/src/proto/channel.pro b/src/proto/channel.pro
index 40742adad..3738edcee 100644
--- a/src/proto/channel.pro
+++ b/src/proto/channel.pro
@@ -31,7 +31,6 @@ void channel_close(channel_T *channel, int invoke_close_cb);
void channel_close_in(channel_T *channel);
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);
channel_T *channel_fd2channel(sock_T fd, ch_part_T *partp);
void channel_handle_events(int only_keep_open);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment