From 6a7593875827374c15484dd4eecd31a88f8c6f77 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 26 Apr 2017 13:10:21 +0200 Subject: channels: implement sockopen() to connect to socket Helped-By: oni-link --- src/nvim/msgpack_rpc/channel.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/nvim/msgpack_rpc') diff --git a/src/nvim/msgpack_rpc/channel.c b/src/nvim/msgpack_rpc/channel.c index cd64e14976..0ff749649b 100644 --- a/src/nvim/msgpack_rpc/channel.c +++ b/src/nvim/msgpack_rpc/channel.c @@ -145,6 +145,25 @@ void channel_from_connection(SocketWatcher *watcher) rstream_start(&channel->data.stream, parse_msgpack, channel); } +uint64_t channel_connect(bool tcp, const char *address, + int timeout, const char **error) +{ + Channel *channel = register_channel(kChannelTypeSocket, 0, NULL); + if (!socket_connect(&main_loop, &channel->data.stream, + tcp, address, timeout, error)) { + decref(channel); + return 0; + } + + incref(channel); // close channel only after the stream is closed + channel->data.stream.internal_close_cb = close_cb; + channel->data.stream.internal_data = channel; + wstream_init(&channel->data.stream, 0); + rstream_init(&channel->data.stream, CHANNEL_BUFFER_SIZE); + rstream_start(&channel->data.stream, parse_msgpack, channel); + return channel->id; +} + /// Sends event/arguments to channel /// /// @param id The channel id. If 0, the event will be sent to all -- cgit