summaryrefslogtreecommitdiffstats
path: root/runtime/doc/channel.txt
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-02-05 22:36:41 +0100
committerBram Moolenaar <Bram@vim.org>2016-02-05 22:36:41 +0100
commit4d919d748e4e435edb135aa5ccf6ee7de9212023 (patch)
tree6930f368370491e5774310f3ce80ab1772525049 /runtime/doc/channel.txt
parenta07fec9c85d062acd9dd433a2e681770f459ba47 (diff)
patch 7.4.1263v7.4.1263
Problem: ch_open() hangs when the server isn't running. Solution: Add a timeout. Use a dict to pass arguments. (Yasuhiro Matsumoto)
Diffstat (limited to 'runtime/doc/channel.txt')
-rw-r--r--runtime/doc/channel.txt36
1 files changed, 25 insertions, 11 deletions
diff --git a/runtime/doc/channel.txt b/runtime/doc/channel.txt
index 31b55cdf3a..0bc98f191e 100644
--- a/runtime/doc/channel.txt
+++ b/runtime/doc/channel.txt
@@ -1,4 +1,4 @@
-*channel.txt* For Vim version 7.4. Last change: 2016 Feb 04
+*channel.txt* For Vim version 7.4. Last change: 2016 Feb 05
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -32,7 +32,7 @@ $VIMRUNTIME/tools/demoserver.py
Run it in one terminal. We will call this T1.
Run Vim in another terminal. Connect to the demo server with: >
- let handle = ch_open('localhost:8765', 'json')
+ let handle = ch_open('localhost:8765')
In T1 you should see:
=== socket opened === ~
@@ -62,23 +62,25 @@ To handle asynchronous communication a callback needs to be used: >
Instead of giving a callback with every send call, it can also be specified
when opening the channel: >
call ch_close(handle)
- let handle = ch_open('localhost:8765', 'json', "MyHandler")
+ let handle = ch_open('localhost:8765', {'callback': "MyHandler"})
call ch_sendexpr(handle, 'hello!', 0)
==============================================================================
2. Opening a channel *channel-open*
To open a channel: >
- let handle = ch_open({address}, {mode}, {callback})
+ let handle = ch_open({address} [, {argdict}])
{address} has the form "hostname:port". E.g., "localhost:8765".
-{mode} can be: *channel-mode*
- "json" - Use JSON, see below; most convenient way
+{argdict} is a dictionary with optional entries:
+
+"mode" can be: *channel-mode*
+ "json" - Use JSON, see below; most convenient way. Default.
"raw" - Use raw messages
*channel-callback*
-{callback} is a function that is called when a message is received that is not
+"callback" is a function that is called when a message is received that is not
handled otherwise. It gets two arguments: the channel handle and the received
message. Example: >
func Handle(handle, msg)
@@ -86,16 +88,28 @@ message. Example: >
endfunc
let handle = ch_open("localhost:8765", 'json', "Handle")
-When {mode} is "json" the "msg" argument is the body of the received message,
+"waittime" is the time to wait for the connection to be made in milliseconds.
+The default is zero, don't wait, which is useful if the server is supposed to
+be running already. A negative number waits forever.
+
+"timeout" is the time to wait for a request when blocking, using
+ch_sendexpr(). Again in millisecons. The default si 2000 (2 seconds).
+
+When "mode" is "json" the "msg" argument is the body of the received message,
converted to Vim types.
-When {mode} is "raw" the "msg" argument is the whole message as a string.
+When "mode" is "raw" the "msg" argument is the whole message as a string.
-When {mode} is "json" the {callback} is optional. When omitted it is only
+When "mode" is "json" the "callback" is optional. When omitted it is only
possible to receive a message after sending one.
The handler can be added or changed later: >
call ch_setcallback(handle, {callback})
-When {callback} is empty (zero or an empty string) the handler is removed.
+When "callback is empty (zero or an empty string) the handler is removed.
+NOT IMPLEMENTED YET
+
+The timeout can be changed later: >
+ call ch_settimeout(handle, {msec})
+NOT IMPLEMENTED YET
Once done with the channel, disconnect it like this: >
call ch_close(handle)