Mercurial > vim
diff src/channel.c @ 8157:74b44d06d3c7 v7.4.1372
commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Feb 20 19:56:13 2016 +0100
patch 7.4.1372
Problem: channel read implementation is incomplete.
Solution: Add ch_read() and options for ch_readraw().
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 20 Feb 2016 20:00:05 +0100 |
parents | 6ee6fb27dcea |
children | d0958e22d9ff |
line wrap: on
line diff
--- a/src/channel.c +++ b/src/channel.c @@ -1696,12 +1696,11 @@ channel_read(channel_T *channel, int par * Returns NULL in case of error or timeout. */ char_u * -channel_read_block(channel_T *channel, int part) +channel_read_block(channel_T *channel, int part, int timeout) { char_u *buf; char_u *msg; ch_mode_T mode = channel->ch_part[part].ch_mode; - int timeout = channel->ch_part[part].ch_timeout; sock_T fd = channel->ch_part[part].ch_fd; char_u *nl; @@ -1753,16 +1752,23 @@ channel_read_block(channel_T *channel, i /* * Read one JSON message with ID "id" from "channel"/"part" and store the * result in "rettv". + * When "id" is -1 accept any message; * Blocks until the message is received or the timeout is reached. */ int -channel_read_json_block(channel_T *channel, int part, int id, typval_T **rettv) +channel_read_json_block( + channel_T *channel, + int part, + int timeout, + int id, + typval_T **rettv) { int more; sock_T fd; ch_log(channel, "Reading JSON"); - channel->ch_part[part].ch_block_id = id; + if (id != -1) + channel->ch_part[part].ch_block_id = id; for (;;) { more = channel_parse_json(channel, part); @@ -1781,10 +1787,9 @@ channel_read_json_block(channel_T *chann if (channel_parse_messages()) continue; - /* Wait for up to the channel timeout. */ + /* Wait for up to the timeout. */ fd = channel->ch_part[part].ch_fd; - if (fd == INVALID_FD || channel_wait(channel, fd, - channel->ch_part[part].ch_timeout) == FAIL) + if (fd == INVALID_FD || channel_wait(channel, fd, timeout) == FAIL) break; channel_read(channel, part, "channel_read_json_block"); } @@ -2161,4 +2166,13 @@ channel_get_mode(channel_T *channel, int return channel->ch_part[part].ch_mode; } +/* + * Return the timeout of "channel"/"part" + */ + int +channel_get_timeout(channel_T *channel, int part) +{ + return channel->ch_part[part].ch_timeout; +} + #endif /* FEAT_CHANNEL */