aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/channel.c39
-rw-r--r--src/nvim/eval.c10
2 files changed, 25 insertions, 24 deletions
diff --git a/src/nvim/channel.c b/src/nvim/channel.c
index 265d4d8b89..2e32af2e9a 100644
--- a/src/nvim/channel.c
+++ b/src/nvim/channel.c
@@ -180,10 +180,12 @@ static Channel *channel_alloc(ChannelStreamType type)
}
/// Not implemented, only logging for now
-void channel_create_event(Channel *chan, char *ext_source)
+void channel_create_event(Channel *chan, const char *ext_source)
{
#if MIN_LOG_LEVEL <= INFO_LOG_LEVEL
- char *stream_desc, *mode_desc, *source;
+ const char *stream_desc;
+ const char *mode_desc;
+ const char *source;
switch (chan->streamtype) {
case kChannelStreamProc:
@@ -223,8 +225,8 @@ void channel_create_event(Channel *chan, char *ext_source)
// external events should be included.
source = ext_source;
} else {
- eval_format_source_name_line((char *)IObuff, sizeof(IObuff));
- source = (char *)IObuff;
+ eval_fmt_source_name_line((char *)IObuff, sizeof(IObuff));
+ source = (const char *)IObuff;
}
ILOG("new channel %" PRIu64 " (%s%s): %s", chan->id, stream_desc,
@@ -392,17 +394,22 @@ uint64_t channel_connect(bool tcp, const char *address,
bool rpc, CallbackReader on_output,
int timeout, const char **error)
{
+ Channel *channel;
+
if (!tcp && rpc) {
char *path = fix_fname(address);
- if (server_owns_pipe_address(path)) {
- // avoid deadlock
- xfree(path);
- return channel_create_internal_rpc();
- }
+ bool loopback = server_owns_pipe_address(path);
xfree(path);
+ if (loopback) {
+ // Create a loopback channel. This avoids deadlock if nvim connects to
+ // its own named pipe.
+ channel = channel_alloc(kChannelStreamInternal);
+ rpc_start(channel);
+ goto end;
+ }
}
- Channel *channel = channel_alloc(kChannelStreamSocket);
+ channel = channel_alloc(kChannelStreamSocket);
if (!socket_connect(&main_loop, &channel->stream.socket,
tcp, address, timeout, error)) {
channel_destroy_early(channel);
@@ -422,7 +429,8 @@ uint64_t channel_connect(bool tcp, const char *address,
rstream_start(&channel->stream.socket, on_socket_output, channel);
}
- channel_create_event(channel, NULL);
+end:
+ channel_create_event(channel, address);
return channel->id;
}
@@ -441,15 +449,6 @@ void channel_from_connection(SocketWatcher *watcher)
channel_create_event(channel, watcher->addr);
}
-/// Creates a loopback channel. This is used to avoid deadlock
-/// when an instance connects to its own named pipe.
-static uint64_t channel_create_internal_rpc(void)
-{
- Channel *channel = channel_alloc(kChannelStreamInternal);
- rpc_start(channel);
- return channel->id;
-}
-
/// Creates an API channel from stdin/stdout. This is used when embedding
/// Neovim
uint64_t channel_from_stdio(bool rpc, CallbackReader on_output,
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 4140eebdf6..feccec85c6 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -22521,11 +22521,13 @@ bool eval_has_provider(const char *name)
}
/// Writes "<sourcing_name>:<sourcing_lnum>" to `buf[bufsize]`.
-void eval_format_source_name_line(char *buf, size_t bufsize)
+void eval_fmt_source_name_line(char *buf, size_t bufsize)
{
- snprintf(buf, bufsize, "%s:%" PRIdLINENR,
- (sourcing_name ? sourcing_name : (char_u *)"?"),
- (sourcing_name ? sourcing_lnum : 0));
+ if (sourcing_name) {
+ snprintf(buf, bufsize, "%s:%" PRIdLINENR, sourcing_name, sourcing_lnum);
+ } else {
+ snprintf(buf, bufsize, "?");
+ }
}
/// ":checkhealth [plugins]"