diff options
author | Josh Rahm <rahm@google.com> | 2022-07-18 19:37:18 +0000 |
---|---|---|
committer | Josh Rahm <rahm@google.com> | 2022-07-18 19:37:18 +0000 |
commit | 308e1940dcd64aa6c344c403d4f9e0dda58d9c5c (patch) | |
tree | 35fe43e01755e0f312650667004487a44d6b7941 /src/nvim/event | |
parent | 96a00c7c588b2f38a2424aeeb4ea3581d370bf2d (diff) | |
parent | e8c94697bcbe23a5c7b07c292b90a6b70aadfa87 (diff) | |
download | rneovim-308e1940dcd64aa6c344c403d4f9e0dda58d9c5c.tar.gz rneovim-308e1940dcd64aa6c344c403d4f9e0dda58d9c5c.tar.bz2 rneovim-308e1940dcd64aa6c344c403d4f9e0dda58d9c5c.zip |
Merge remote-tracking branch 'upstream/master' into rahm
Diffstat (limited to 'src/nvim/event')
-rw-r--r-- | src/nvim/event/loop.c | 5 | ||||
-rw-r--r-- | src/nvim/event/loop.h | 7 | ||||
-rw-r--r-- | src/nvim/event/multiqueue.c | 1 | ||||
-rw-r--r-- | src/nvim/event/multiqueue.h | 1 | ||||
-rw-r--r-- | src/nvim/event/process.c | 6 | ||||
-rw-r--r-- | src/nvim/event/process.h | 1 | ||||
-rw-r--r-- | src/nvim/event/rstream.c | 21 | ||||
-rw-r--r-- | src/nvim/event/rstream.h | 1 | ||||
-rw-r--r-- | src/nvim/event/signal.c | 1 | ||||
-rw-r--r-- | src/nvim/event/socket.c | 21 | ||||
-rw-r--r-- | src/nvim/event/time.c | 1 |
11 files changed, 30 insertions, 36 deletions
diff --git a/src/nvim/event/loop.c b/src/nvim/event/loop.c index 89fced59c5..1b5cc23b09 100644 --- a/src/nvim/event/loop.c +++ b/src/nvim/event/loop.c @@ -13,7 +13,6 @@ # include "event/loop.c.generated.h" #endif - void loop_init(Loop *loop, void *data) { uv_loop_init(&loop->uv); @@ -28,6 +27,7 @@ void loop_init(Loop *loop, void *data) uv_signal_init(&loop->uv, &loop->children_watcher); uv_timer_init(&loop->uv, &loop->children_kill_timer); uv_timer_init(&loop->uv, &loop->poll_timer); + uv_timer_init(&loop->uv, &loop->exit_delay_timer); loop->poll_timer.data = xmalloc(sizeof(bool)); // "timeout expired" flag } @@ -137,13 +137,14 @@ bool loop_close(Loop *loop, bool wait) uv_close((uv_handle_t *)&loop->children_watcher, NULL); uv_close((uv_handle_t *)&loop->children_kill_timer, NULL); uv_close((uv_handle_t *)&loop->poll_timer, timer_close_cb); + uv_close((uv_handle_t *)&loop->exit_delay_timer, NULL); uv_close((uv_handle_t *)&loop->async, NULL); uint64_t start = wait ? os_hrtime() : 0; bool didstop = false; while (true) { // Run the loop to tickle close-callbacks (which should then free memory). // Use UV_RUN_NOWAIT to avoid a hang. #11820 - uv_run(&loop->uv, didstop ? UV_RUN_DEFAULT : UV_RUN_NOWAIT); + uv_run(&loop->uv, didstop ? UV_RUN_DEFAULT : UV_RUN_NOWAIT); // -V547 if ((uv_loop_close(&loop->uv) != UV_EBUSY) || !wait) { break; } diff --git a/src/nvim/event/loop.h b/src/nvim/event/loop.h index acd1d1a334..65980c6c05 100644 --- a/src/nvim/event/loop.h +++ b/src/nvim/event/loop.h @@ -10,8 +10,8 @@ typedef void *WatcherPtr; -#define _noop(x) -KLIST_INIT(WatcherPtr, WatcherPtr, _noop) +#define _NOOP(x) +KLIST_INIT(WatcherPtr, WatcherPtr, _NOOP) typedef struct loop { uv_loop_t uv; @@ -36,6 +36,8 @@ typedef struct loop { // generic timer, used by loop_poll_events() uv_timer_t poll_timer; + uv_timer_t exit_delay_timer; + uv_async_t async; uv_mutex_t mutex; int recursive; @@ -82,7 +84,6 @@ typedef struct loop { } \ } while (0) - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "event/loop.h.generated.h" #endif diff --git a/src/nvim/event/multiqueue.c b/src/nvim/event/multiqueue.c index a90cbc4e80..40d20033e0 100644 --- a/src/nvim/event/multiqueue.c +++ b/src/nvim/event/multiqueue.c @@ -82,7 +82,6 @@ typedef struct { int refcount; } MulticastEvent; ///< Event present on multiple queues. - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "event/multiqueue.c.generated.h" #endif diff --git a/src/nvim/event/multiqueue.h b/src/nvim/event/multiqueue.h index dc60fbb4c7..2c5ba9d436 100644 --- a/src/nvim/event/multiqueue.h +++ b/src/nvim/event/multiqueue.h @@ -12,7 +12,6 @@ typedef void (*PutCallback)(MultiQueue *multiq, void *data); #define multiqueue_put(q, h, ...) \ multiqueue_put_event(q, event_create(h, __VA_ARGS__)); - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "event/multiqueue.h.generated.h" #endif diff --git a/src/nvim/event/process.c b/src/nvim/event/process.c index dae4dad16d..e029f778f6 100644 --- a/src/nvim/event/process.c +++ b/src/nvim/event/process.c @@ -120,7 +120,7 @@ int process_spawn(Process *proc, bool in, bool out, bool err) proc->internal_close_cb = decref; proc->refcount++; kl_push(WatcherPtr, proc->loop->children, proc); - DLOG("new: pid=%d argv=[%s]", proc->pid, *proc->argv); + DLOG("new: pid=%d argv=[%s]", proc->pid, proc->argv[0]); return 0; } @@ -237,7 +237,7 @@ void process_stop(Process *proc) FUNC_ATTR_NONNULL_ALL KILL_TIMEOUT_MS, 0); } -// Frees process-owned resources. +/// Frees process-owned resources. void process_free(Process *proc) FUNC_ATTR_NONNULL_ALL { if (proc->argv != NULL) { @@ -386,11 +386,13 @@ static void process_close_handles(void **argv) { Process *proc = argv[0]; + exit_need_delay++; flush_stream(proc, &proc->out); flush_stream(proc, &proc->err); process_close_streams(proc); process_close(proc); + exit_need_delay--; } static void on_process_exit(Process *proc) diff --git a/src/nvim/event/process.h b/src/nvim/event/process.h index c20feb2c7a..30254bfe07 100644 --- a/src/nvim/event/process.h +++ b/src/nvim/event/process.h @@ -33,7 +33,6 @@ struct process { MultiQueue *events; }; - static inline Process process_init(Loop *loop, ProcessType type, void *data) { return (Process) { diff --git a/src/nvim/event/rstream.c b/src/nvim/event/rstream.c index 3c43d1f98d..2847788ef8 100644 --- a/src/nvim/event/rstream.c +++ b/src/nvim/event/rstream.c @@ -11,8 +11,8 @@ #include "nvim/event/loop.h" #include "nvim/event/rstream.h" #include "nvim/log.h" -#include "nvim/memory.h" #include "nvim/main.h" +#include "nvim/memory.h" #include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS @@ -42,7 +42,6 @@ void rstream_init(Stream *stream, size_t bufsize) stream->buffer->nonfull_cb = on_rbuffer_nonfull; } - /// Starts watching for events from a `Stream` instance. /// /// @param stream The `Stream` instance @@ -85,7 +84,7 @@ static void on_rbuffer_nonfull(RBuffer *buf, void *data) // Callbacks used by libuv -// Called by libuv to allocate memory for reading. +/// Called by libuv to allocate memory for reading. static void alloc_cb(uv_handle_t *handle, size_t suggested, uv_buf_t *buf) { Stream *stream = handle->data; @@ -95,9 +94,9 @@ static void alloc_cb(uv_handle_t *handle, size_t suggested, uv_buf_t *buf) buf->len = UV_BUF_LEN(write_count); } -// Callback invoked by libuv after it copies the data into the buffer provided -// by `alloc_cb`. This is also called on EOF or when `alloc_cb` returns a -// 0-length buffer. +/// Callback invoked by libuv after it copies the data into the buffer provided +/// by `alloc_cb`. This is also called on EOF or when `alloc_cb` returns a +/// 0-length buffer. static void read_cb(uv_stream_t *uvstream, ssize_t cnt, const uv_buf_t *buf) { Stream *stream = uvstream->data; @@ -134,11 +133,11 @@ static void read_cb(uv_stream_t *uvstream, ssize_t cnt, const uv_buf_t *buf) invoke_read_cb(stream, nread, false); } -// Called by the by the 'idle' handle to emulate a reading event -// -// Idle callbacks are invoked once per event loop: -// - to perform some very low priority activity. -// - to keep the loop "alive" (so there is always an event to process) +/// Called by the by the 'idle' handle to emulate a reading event +/// +/// Idle callbacks are invoked once per event loop: +/// - to perform some very low priority activity. +/// - to keep the loop "alive" (so there is always an event to process) static void fread_idle_cb(uv_idle_t *handle) { uv_fs_t req; diff --git a/src/nvim/event/rstream.h b/src/nvim/event/rstream.h index 77418c59a2..23ed00bfea 100644 --- a/src/nvim/event/rstream.h +++ b/src/nvim/event/rstream.h @@ -8,7 +8,6 @@ #include "nvim/event/loop.h" #include "nvim/event/stream.h" - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "event/rstream.h.generated.h" #endif diff --git a/src/nvim/event/signal.c b/src/nvim/event/signal.c index fec46da4ff..4a45a2ec2f 100644 --- a/src/nvim/event/signal.c +++ b/src/nvim/event/signal.c @@ -10,7 +10,6 @@ # include "event/signal.c.generated.h" #endif - void signal_watcher_init(Loop *loop, SignalWatcher *watcher, void *data) FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_NONNULL_ARG(2) { diff --git a/src/nvim/event/socket.c b/src/nvim/event/socket.c index 7948a7be83..9496a568b9 100644 --- a/src/nvim/event/socket.c +++ b/src/nvim/event/socket.c @@ -38,7 +38,7 @@ int socket_watcher_init(Loop *loop, SocketWatcher *watcher, const char *endpoint char *port = host_end + 1; intmax_t iport; - int ok = try_getdigits(&(char_u *){ (char_u *)port }, &iport); + int ok = try_getdigits(&(char *){ port }, &iport); if (!ok || iport < 0 || iport > UINT16_MAX) { ELOG("Invalid port: %s", port); return UV_EINVAL; @@ -53,10 +53,8 @@ int socket_watcher_init(Loop *loop, SocketWatcher *watcher, const char *endpoint uv_getaddrinfo_t request; int retval = uv_getaddrinfo(&loop->uv, &request, NULL, addr, port, - &(struct addrinfo){ - .ai_family = AF_UNSPEC, - .ai_socktype = SOCK_STREAM, - }); + &(struct addrinfo){ .ai_family = AF_UNSPEC, + .ai_socktype = SOCK_STREAM, }); if (retval != 0) { ELOG("Host lookup failed: %s", endpoint); return retval; @@ -103,13 +101,12 @@ int socket_watcher_start(SocketWatcher *watcher, int backlog, socket_cb cb) // contain 0 in this case, unless uv_tcp_getsockname() is used first. uv_tcp_getsockname(&watcher->uv.tcp.handle, (struct sockaddr *)&sas, &(int){ sizeof(sas) }); - uint16_t port = (uint16_t)( - (sas.ss_family == AF_INET) - ? (STRUCT_CAST(struct sockaddr_in, &sas))->sin_port - : (STRUCT_CAST(struct sockaddr_in6, &sas))->sin6_port); + uint16_t port = (uint16_t)((sas.ss_family == AF_INET) + ? (STRUCT_CAST(struct sockaddr_in, &sas))->sin_port + : (STRUCT_CAST(struct sockaddr_in6, &sas))->sin6_port); // v:servername uses the string from watcher->addr size_t len = strlen(watcher->addr); - snprintf(watcher->addr+len, sizeof(watcher->addr)-len, ":%" PRIu16, + snprintf(watcher->addr + len, sizeof(watcher->addr) - len, ":%" PRIu16, ntohs(port)); break; } @@ -127,7 +124,7 @@ int socket_watcher_start(SocketWatcher *watcher, int backlog, socket_cb cb) if (result == UV_EACCES) { // Libuv converts ENOENT to EACCES for Windows compatibility, but if // the parent directory does not exist, ENOENT would be more accurate. - *path_tail((char_u *)watcher->addr) = NUL; + *path_tail(watcher->addr) = NUL; if (!os_path_exists((char_u *)watcher->addr)) { result = UV_ENOENT; } @@ -228,7 +225,7 @@ bool socket_connect(Loop *loop, Stream *stream, bool is_tcp, const char *address .ai_socktype = SOCK_STREAM, .ai_flags = AI_NUMERICSERV }; int retval = uv_getaddrinfo(&loop->uv, &addr_req, NULL, - addr, host_end+1, &hints); + addr, host_end + 1, &hints); if (retval != 0) { *error = _("failed to lookup host or port"); goto cleanup; diff --git a/src/nvim/event/time.c b/src/nvim/event/time.c index aa7b9cf2a1..c997e3c558 100644 --- a/src/nvim/event/time.c +++ b/src/nvim/event/time.c @@ -11,7 +11,6 @@ # include "event/time.c.generated.h" #endif - void time_watcher_init(Loop *loop, TimeWatcher *watcher, void *data) FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_NONNULL_ARG(2) { |