mirror of
https://github.com/neovim/neovim.git
synced 2025-10-08 10:56:31 +00:00
log: channel registration
This commit is contained in:
@@ -117,12 +117,11 @@ void channel_teardown(void)
|
|||||||
/// Creates an API channel by starting a process and connecting to its
|
/// Creates an API channel by starting a process and connecting to its
|
||||||
/// stdin/stdout. stderr is handled by the job infrastructure.
|
/// stdin/stdout. stderr is handled by the job infrastructure.
|
||||||
///
|
///
|
||||||
/// @param argv The argument vector for the process. [consumed]
|
/// @return Channel id (> 0), on success. 0, on error.
|
||||||
/// @return The channel id (> 0), on success.
|
|
||||||
/// 0, on error.
|
|
||||||
uint64_t channel_from_process(Process *proc, uint64_t id)
|
uint64_t channel_from_process(Process *proc, uint64_t id)
|
||||||
{
|
{
|
||||||
Channel *channel = register_channel(kChannelTypeProc, id, proc->events);
|
Channel *channel = register_channel(kChannelTypeProc, id, proc->events,
|
||||||
|
proc->argv);
|
||||||
incref(channel); // process channels are only closed by the exit_cb
|
incref(channel); // process channels are only closed by the exit_cb
|
||||||
channel->data.proc = proc;
|
channel->data.proc = proc;
|
||||||
|
|
||||||
@@ -138,7 +137,7 @@ uint64_t channel_from_process(Process *proc, uint64_t id)
|
|||||||
/// @param watcher The SocketWatcher ready to accept the connection
|
/// @param watcher The SocketWatcher ready to accept the connection
|
||||||
void channel_from_connection(SocketWatcher *watcher)
|
void channel_from_connection(SocketWatcher *watcher)
|
||||||
{
|
{
|
||||||
Channel *channel = register_channel(kChannelTypeSocket, 0, NULL);
|
Channel *channel = register_channel(kChannelTypeSocket, 0, NULL, NULL);
|
||||||
socket_watcher_accept(watcher, &channel->data.stream);
|
socket_watcher_accept(watcher, &channel->data.stream);
|
||||||
incref(channel); // close channel only after the stream is closed
|
incref(channel); // close channel only after the stream is closed
|
||||||
channel->data.stream.internal_close_cb = close_cb;
|
channel->data.stream.internal_close_cb = close_cb;
|
||||||
@@ -161,7 +160,7 @@ uint64_t channel_connect(bool tcp, const char *address,
|
|||||||
xfree(path);
|
xfree(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
Channel *channel = register_channel(kChannelTypeSocket, 0, NULL);
|
Channel *channel = register_channel(kChannelTypeSocket, 0, NULL, NULL);
|
||||||
if (!socket_connect(&main_loop, &channel->data.stream,
|
if (!socket_connect(&main_loop, &channel->data.stream,
|
||||||
tcp, address, timeout, error)) {
|
tcp, address, timeout, error)) {
|
||||||
decref(channel);
|
decref(channel);
|
||||||
@@ -333,7 +332,7 @@ bool channel_close(uint64_t id)
|
|||||||
/// Neovim
|
/// Neovim
|
||||||
void channel_from_stdio(void)
|
void channel_from_stdio(void)
|
||||||
{
|
{
|
||||||
Channel *channel = register_channel(kChannelTypeStdio, 0, NULL);
|
Channel *channel = register_channel(kChannelTypeStdio, 0, NULL, NULL);
|
||||||
incref(channel); // stdio channels are only closed on exit
|
incref(channel); // stdio channels are only closed on exit
|
||||||
// read stream
|
// read stream
|
||||||
rstream_init_fd(&main_loop, &channel->data.std.in, 0, CHANNEL_BUFFER_SIZE);
|
rstream_init_fd(&main_loop, &channel->data.std.in, 0, CHANNEL_BUFFER_SIZE);
|
||||||
@@ -346,7 +345,7 @@ void channel_from_stdio(void)
|
|||||||
/// when an instance connects to its own named pipe.
|
/// when an instance connects to its own named pipe.
|
||||||
uint64_t channel_create_internal(void)
|
uint64_t channel_create_internal(void)
|
||||||
{
|
{
|
||||||
Channel *channel = register_channel(kChannelTypeInternal, 0, NULL);
|
Channel *channel = register_channel(kChannelTypeInternal, 0, NULL, NULL);
|
||||||
incref(channel); // internal channel lives until process exit
|
incref(channel); // internal channel lives until process exit
|
||||||
return channel->id;
|
return channel->id;
|
||||||
}
|
}
|
||||||
@@ -746,7 +745,7 @@ static void close_cb(Stream *stream, void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Channel *register_channel(ChannelType type, uint64_t id,
|
static Channel *register_channel(ChannelType type, uint64_t id,
|
||||||
MultiQueue *events)
|
MultiQueue *events, char **argv)
|
||||||
{
|
{
|
||||||
Channel *rv = xmalloc(sizeof(Channel));
|
Channel *rv = xmalloc(sizeof(Channel));
|
||||||
rv->events = events ? events : multiqueue_new_child(main_loop.events);
|
rv->events = events ? events : multiqueue_new_child(main_loop.events);
|
||||||
@@ -761,6 +760,33 @@ static Channel *register_channel(ChannelType type, uint64_t id,
|
|||||||
kv_init(rv->call_stack);
|
kv_init(rv->call_stack);
|
||||||
kv_init(rv->delayed_notifications);
|
kv_init(rv->delayed_notifications);
|
||||||
pmap_put(uint64_t)(channels, rv->id, rv);
|
pmap_put(uint64_t)(channels, rv->id, rv);
|
||||||
|
|
||||||
|
#if MIN_LOG_LEVEL <= DEBUG_LOG_LEVEL
|
||||||
|
switch(type) {
|
||||||
|
case kChannelTypeSocket:
|
||||||
|
DLOG("register ch %" PRIu64 " type=socket", rv->id);
|
||||||
|
break;
|
||||||
|
case kChannelTypeProc: {
|
||||||
|
char buf[IOSIZE];
|
||||||
|
buf[0] = '\0';
|
||||||
|
char **p = argv;
|
||||||
|
while (p != NULL && *p != NULL) {
|
||||||
|
xstrlcat(buf, *p, sizeof(buf));
|
||||||
|
xstrlcat(buf, " ", sizeof(buf));
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
DLOG("register ch %" PRIu64 " type=proc argv=%s", rv->id, buf);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case kChannelTypeStdio:
|
||||||
|
DLOG("register ch %" PRIu64 " type=stdio", rv->id);
|
||||||
|
break;
|
||||||
|
case kChannelTypeInternal:
|
||||||
|
DLOG("register ch %" PRIu64 " type=internal", rv->id);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user