aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os/channel.c
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2014-09-10 09:32:29 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-09-12 13:25:29 -0300
commit50609029301d0baac36d7500c2d80da9efb41861 (patch)
treebcb0c40efe2c9b30edb437929429a12b61f75fd4 /src/nvim/os/channel.c
parent03f4d17fc9d72c8862daf575804e0104e3aeb31b (diff)
downloadrneovim-50609029301d0baac36d7500c2d80da9efb41861.tar.gz
rneovim-50609029301d0baac36d7500c2d80da9efb41861.tar.bz2
rneovim-50609029301d0baac36d7500c2d80da9efb41861.zip
api/msgpack-rpc: Implement `channel_close` and expose to vimscript
Simple function for closing a channel by id
Diffstat (limited to 'src/nvim/os/channel.c')
-rw-r--r--src/nvim/os/channel.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/nvim/os/channel.c b/src/nvim/os/channel.c
index 5a42db112e..ad8f378dfc 100644
--- a/src/nvim/os/channel.c
+++ b/src/nvim/os/channel.c
@@ -267,6 +267,23 @@ void channel_unsubscribe(uint64_t id, char *event)
unsubscribe(channel, event);
}
+/// Closes a channel
+///
+/// @param id The channel id
+/// @return true if successful, false otherwise
+bool channel_close(uint64_t id)
+{
+ Channel *channel;
+
+ if (!(channel = pmap_get(uint64_t)(channels, id)) || !channel->enabled) {
+ return false;
+ }
+
+ channel_kill(channel);
+ channel->enabled = false;
+ return true;
+}
+
/// Creates an API channel from stdin/stdout. This is used when embedding
/// Neovim
static void channel_from_stdio(void)
@@ -496,7 +513,13 @@ static void close_channel(Channel *channel)
pmap_free(cstr_t)(channel->subscribed_events);
kv_destroy(channel->call_stack);
+ channel_kill(channel);
+ free(channel);
+}
+
+static void channel_kill(Channel *channel)
+{
if (channel->is_job) {
if (channel->data.job) {
job_stop(channel->data.job);
@@ -511,8 +534,6 @@ static void close_channel(Channel *channel)
mch_exit(0);
}
}
-
- free(channel);
}
static void close_cb(uv_handle_t *handle)