mirror of
https://github.com/neovim/neovim.git
synced 2025-10-07 10:26:31 +00:00
channels: implement sockopen() to connect to socket
Helped-By: oni-link <knil.ino@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user