comparison 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
comparison
equal deleted inserted replaced
8156:d5ab593ed881 8157:74b44d06d3c7
1694 * read or the timeout expires. 1694 * read or the timeout expires.
1695 * Returns what was read in allocated memory. 1695 * Returns what was read in allocated memory.
1696 * Returns NULL in case of error or timeout. 1696 * Returns NULL in case of error or timeout.
1697 */ 1697 */
1698 char_u * 1698 char_u *
1699 channel_read_block(channel_T *channel, int part) 1699 channel_read_block(channel_T *channel, int part, int timeout)
1700 { 1700 {
1701 char_u *buf; 1701 char_u *buf;
1702 char_u *msg; 1702 char_u *msg;
1703 ch_mode_T mode = channel->ch_part[part].ch_mode; 1703 ch_mode_T mode = channel->ch_part[part].ch_mode;
1704 int timeout = channel->ch_part[part].ch_timeout;
1705 sock_T fd = channel->ch_part[part].ch_fd; 1704 sock_T fd = channel->ch_part[part].ch_fd;
1706 char_u *nl; 1705 char_u *nl;
1707 1706
1708 ch_logsn(channel, "Blocking %s read, timeout: %d msec", 1707 ch_logsn(channel, "Blocking %s read, timeout: %d msec",
1709 mode == MODE_RAW ? "RAW" : "NL", timeout); 1708 mode == MODE_RAW ? "RAW" : "NL", timeout);
1751 } 1750 }
1752 1751
1753 /* 1752 /*
1754 * Read one JSON message with ID "id" from "channel"/"part" and store the 1753 * Read one JSON message with ID "id" from "channel"/"part" and store the
1755 * result in "rettv". 1754 * result in "rettv".
1755 * When "id" is -1 accept any message;
1756 * Blocks until the message is received or the timeout is reached. 1756 * Blocks until the message is received or the timeout is reached.
1757 */ 1757 */
1758 int 1758 int
1759 channel_read_json_block(channel_T *channel, int part, int id, typval_T **rettv) 1759 channel_read_json_block(
1760 channel_T *channel,
1761 int part,
1762 int timeout,
1763 int id,
1764 typval_T **rettv)
1760 { 1765 {
1761 int more; 1766 int more;
1762 sock_T fd; 1767 sock_T fd;
1763 1768
1764 ch_log(channel, "Reading JSON"); 1769 ch_log(channel, "Reading JSON");
1765 channel->ch_part[part].ch_block_id = id; 1770 if (id != -1)
1771 channel->ch_part[part].ch_block_id = id;
1766 for (;;) 1772 for (;;)
1767 { 1773 {
1768 more = channel_parse_json(channel, part); 1774 more = channel_parse_json(channel, part);
1769 1775
1770 /* search for messsage "id" */ 1776 /* search for messsage "id" */
1779 /* Handle any other messages in the queue. If done some more 1785 /* Handle any other messages in the queue. If done some more
1780 * messages may have arrived. */ 1786 * messages may have arrived. */
1781 if (channel_parse_messages()) 1787 if (channel_parse_messages())
1782 continue; 1788 continue;
1783 1789
1784 /* Wait for up to the channel timeout. */ 1790 /* Wait for up to the timeout. */
1785 fd = channel->ch_part[part].ch_fd; 1791 fd = channel->ch_part[part].ch_fd;
1786 if (fd == INVALID_FD || channel_wait(channel, fd, 1792 if (fd == INVALID_FD || channel_wait(channel, fd, timeout) == FAIL)
1787 channel->ch_part[part].ch_timeout) == FAIL)
1788 break; 1793 break;
1789 channel_read(channel, part, "channel_read_json_block"); 1794 channel_read(channel, part, "channel_read_json_block");
1790 } 1795 }
1791 } 1796 }
1792 channel->ch_part[part].ch_block_id = 0; 1797 channel->ch_part[part].ch_block_id = 0;
2159 if (channel == NULL) 2164 if (channel == NULL)
2160 return MODE_JSON; 2165 return MODE_JSON;
2161 return channel->ch_part[part].ch_mode; 2166 return channel->ch_part[part].ch_mode;
2162 } 2167 }
2163 2168
2169 /*
2170 * Return the timeout of "channel"/"part"
2171 */
2172 int
2173 channel_get_timeout(channel_T *channel, int part)
2174 {
2175 return channel->ch_part[part].ch_timeout;
2176 }
2177
2164 #endif /* FEAT_CHANNEL */ 2178 #endif /* FEAT_CHANNEL */