diff options
Diffstat (limited to 'src/nvim/event')
-rw-r--r-- | src/nvim/event/libuv_process.c | 7 | ||||
-rw-r--r-- | src/nvim/event/loop.c | 1 | ||||
-rw-r--r-- | src/nvim/event/multiqueue.c | 7 | ||||
-rw-r--r-- | src/nvim/event/process.c | 74 | ||||
-rw-r--r-- | src/nvim/event/rstream.c | 28 | ||||
-rw-r--r-- | src/nvim/event/socket.c | 38 | ||||
-rw-r--r-- | src/nvim/event/stream.c | 9 | ||||
-rw-r--r-- | src/nvim/event/time.c | 4 | ||||
-rw-r--r-- | src/nvim/event/wstream.c | 12 |
9 files changed, 80 insertions, 100 deletions
diff --git a/src/nvim/event/libuv_process.c b/src/nvim/event/libuv_process.c index c02f730431..0251ea9957 100644 --- a/src/nvim/event/libuv_process.c +++ b/src/nvim/event/libuv_process.c @@ -2,14 +2,13 @@ // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com #include <assert.h> - #include <uv.h> +#include "nvim/event/libuv_process.h" #include "nvim/event/loop.h" +#include "nvim/event/process.h" #include "nvim/event/rstream.h" #include "nvim/event/wstream.h" -#include "nvim/event/process.h" -#include "nvim/event/libuv_process.h" #include "nvim/log.h" #include "nvim/macros.h" #include "nvim/os/os.h" @@ -68,7 +67,7 @@ int libuv_process_spawn(LibuvProcess *uvproc) #ifdef WIN32 // pipe must be readable for IOCP to work on Windows. uvproc->uvstdio[1].flags |= proc->overlapped ? - (UV_READABLE_PIPE | UV_OVERLAPPED_PIPE) : 0; + (UV_READABLE_PIPE | UV_OVERLAPPED_PIPE) : 0; #endif uvproc->uvstdio[1].data.stream = STRUCT_CAST(uv_stream_t, &proc->out.uv.pipe); diff --git a/src/nvim/event/loop.c b/src/nvim/event/loop.c index e341513ae1..892c46dd04 100644 --- a/src/nvim/event/loop.c +++ b/src/nvim/event/loop.c @@ -3,7 +3,6 @@ #include <stdarg.h> #include <stdint.h> - #include <uv.h> #include "nvim/event/loop.h" diff --git a/src/nvim/event/multiqueue.c b/src/nvim/event/multiqueue.c index f534fc483f..a90cbc4e80 100644 --- a/src/nvim/event/multiqueue.c +++ b/src/nvim/event/multiqueue.c @@ -49,8 +49,6 @@ #include <stdarg.h> #include <stdbool.h> #include <stdint.h> - - #include <uv.h> #include "nvim/event/multiqueue.h" @@ -89,7 +87,7 @@ typedef struct { # include "event/multiqueue.c.generated.h" #endif -static Event NILEVENT = { .handler = NULL, .argv = {NULL} }; +static Event NILEVENT = { .handler = NULL, .argv = { NULL } }; MultiQueue *multiqueue_new_parent(PutCallback put_cb, void *data) { @@ -104,8 +102,7 @@ MultiQueue *multiqueue_new_child(MultiQueue *parent) return multiqueue_new(parent, NULL, NULL); } -static MultiQueue *multiqueue_new(MultiQueue *parent, PutCallback put_cb, - void *data) +static MultiQueue *multiqueue_new(MultiQueue *parent, PutCallback put_cb, void *data) { MultiQueue *rv = xmalloc(sizeof(MultiQueue)); QUEUE_INIT(&rv->headtail); diff --git a/src/nvim/event/process.c b/src/nvim/event/process.c index 8b366d0f3c..dae4dad16d 100644 --- a/src/nvim/event/process.c +++ b/src/nvim/event/process.c @@ -3,20 +3,19 @@ #include <assert.h> #include <stdlib.h> - #include <uv.h> -#include "nvim/os/shell.h" +#include "nvim/event/libuv_process.h" #include "nvim/event/loop.h" +#include "nvim/event/process.h" #include "nvim/event/rstream.h" #include "nvim/event/wstream.h" -#include "nvim/event/process.h" -#include "nvim/event/libuv_process.h" -#include "nvim/os/process.h" -#include "nvim/os/pty_process.h" #include "nvim/globals.h" -#include "nvim/macros.h" #include "nvim/log.h" +#include "nvim/macros.h" +#include "nvim/os/process.h" +#include "nvim/os/pty_process.h" +#include "nvim/os/shell.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "event/process.c.generated.h" @@ -62,14 +61,14 @@ int process_spawn(Process *proc, bool in, bool out, bool err) int status; switch (proc->type) { - case kProcessTypeUv: - status = libuv_process_spawn((LibuvProcess *)proc); - break; - case kProcessTypePty: - status = pty_process_spawn((PtyProcess *)proc); - break; - default: - abort(); + case kProcessTypeUv: + status = libuv_process_spawn((LibuvProcess *)proc); + break; + case kProcessTypePty: + status = pty_process_spawn((PtyProcess *)proc); + break; + default: + abort(); } if (status) { @@ -139,9 +138,8 @@ void process_teardown(Loop *loop) FUNC_ATTR_NONNULL_ALL } // Wait until all children exit and all close events are processed. - LOOP_PROCESS_EVENTS_UNTIL( - loop, loop->events, -1, - kl_empty(loop->children) && multiqueue_empty(loop->events)); + LOOP_PROCESS_EVENTS_UNTIL(loop, loop->events, -1, + kl_empty(loop->children) && multiqueue_empty(loop->events)); pty_process_teardown(loop); } @@ -189,7 +187,7 @@ int process_wait(Process *proc, int ms, MultiQueue *events) // We can only return if all streams/handles are closed and the job // exited. LOOP_PROCESS_EVENTS_UNTIL(proc->loop, events, -1, - proc->refcount == 1); + proc->refcount == 1); } else { LOOP_PROCESS_EVENTS(proc->loop, events, 0); } @@ -222,16 +220,16 @@ void process_stop(Process *proc) FUNC_ATTR_NONNULL_ALL proc->exit_signal = SIGTERM; switch (proc->type) { - case kProcessTypeUv: - os_proc_tree_kill(proc->pid, SIGTERM); - break; - case kProcessTypePty: - // close all streams for pty processes to send SIGHUP to the process - process_close_streams(proc); - pty_process_close_master((PtyProcess *)proc); - break; - default: - abort(); + case kProcessTypeUv: + os_proc_tree_kill(proc->pid, SIGTERM); + break; + case kProcessTypePty: + // close all streams for pty processes to send SIGHUP to the process + process_close_streams(proc); + pty_process_close_master((PtyProcess *)proc); + break; + default: + abort(); } // (Re)start timer to verify that stopped process(es) died. @@ -325,14 +323,14 @@ static void process_close(Process *proc) } switch (proc->type) { - case kProcessTypeUv: - libuv_process_close((LibuvProcess *)proc); - break; - case kProcessTypePty: - pty_process_close((PtyProcess *)proc); - break; - default: - abort(); + case kProcessTypeUv: + libuv_process_close((LibuvProcess *)proc); + break; + case kProcessTypePty: + pty_process_close((PtyProcess *)proc); + break; + default: + abort(); } } @@ -369,7 +367,7 @@ static void flush_stream(Process *proc, Stream *stream) // Poll for data and process the generated events. loop_poll_events(proc->loop, 0); if (stream->events) { - multiqueue_process_events(stream->events); + multiqueue_process_events(stream->events); } // Stream can be closed if it is empty. diff --git a/src/nvim/event/rstream.c b/src/nvim/event/rstream.c index efa56932d2..f070c8179f 100644 --- a/src/nvim/event/rstream.c +++ b/src/nvim/event/rstream.c @@ -2,19 +2,18 @@ // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com #include <assert.h> -#include <stdint.h> #include <stdbool.h> +#include <stdint.h> #include <stdlib.h> - #include <uv.h> -#include "nvim/event/rstream.h" #include "nvim/ascii.h" -#include "nvim/vim.h" -#include "nvim/memory.h" +#include "nvim/event/loop.h" +#include "nvim/event/rstream.h" #include "nvim/log.h" +#include "nvim/memory.h" #include "nvim/misc1.h" -#include "nvim/event/loop.h" +#include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "event/rstream.c.generated.h" @@ -160,14 +159,13 @@ static void fread_idle_cb(uv_idle_t *handle) } // Synchronous read - uv_fs_read( - handle->loop, - &req, - stream->fd, - &stream->uvbuf, - 1, - (int64_t) stream->fpos, - NULL); + uv_fs_read(handle->loop, + &req, + stream->fd, + &stream->uvbuf, + 1, + (int64_t)stream->fpos, + NULL); uv_fs_req_cleanup(&req); @@ -178,7 +176,7 @@ static void fread_idle_cb(uv_idle_t *handle) } // no errors (req.result (ssize_t) is positive), it's safe to cast. - size_t nread = (size_t) req.result; + size_t nread = (size_t)req.result; rbuffer_produced(stream->buffer, nread); stream->fpos += nread; invoke_read_cb(stream, nread, false); diff --git a/src/nvim/event/socket.c b/src/nvim/event/socket.c index 23228aa63a..7948a7be83 100644 --- a/src/nvim/event/socket.c +++ b/src/nvim/event/socket.c @@ -3,30 +3,28 @@ #include <assert.h> #include <stdint.h> - #include <uv.h> +#include "nvim/ascii.h" +#include "nvim/charset.h" #include "nvim/event/loop.h" -#include "nvim/event/socket.h" #include "nvim/event/rstream.h" +#include "nvim/event/socket.h" #include "nvim/event/wstream.h" -#include "nvim/os/os.h" -#include "nvim/ascii.h" -#include "nvim/vim.h" -#include "nvim/strings.h" -#include "nvim/path.h" +#include "nvim/log.h" +#include "nvim/macros.h" #include "nvim/main.h" #include "nvim/memory.h" -#include "nvim/macros.h" -#include "nvim/charset.h" -#include "nvim/log.h" +#include "nvim/os/os.h" +#include "nvim/path.h" +#include "nvim/strings.h" +#include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "event/socket.c.generated.h" #endif -int socket_watcher_init(Loop *loop, SocketWatcher *watcher, - const char *endpoint) +int socket_watcher_init(Loop *loop, SocketWatcher *watcher, const char *endpoint) FUNC_ATTR_NONNULL_ALL { xstrlcpy(watcher->addr, endpoint, sizeof(watcher->addr)); @@ -56,9 +54,9 @@ int socket_watcher_init(Loop *loop, SocketWatcher *watcher, int retval = uv_getaddrinfo(&loop->uv, &request, NULL, addr, port, &(struct addrinfo){ - .ai_family = AF_UNSPEC, - .ai_socktype = SOCK_STREAM, - }); + .ai_family = AF_UNSPEC, + .ai_socktype = SOCK_STREAM, + }); if (retval != 0) { ELOG("Host lookup failed: %s", endpoint); return retval; @@ -106,7 +104,7 @@ int socket_watcher_start(SocketWatcher *watcher, int backlog, socket_cb cb) uv_tcp_getsockname(&watcher->uv.tcp.handle, (struct sockaddr *)&sas, &(int){ sizeof(sas) }); uint16_t port = (uint16_t)( - (sas.ss_family == AF_INET) + (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 @@ -183,7 +181,7 @@ static void connection_cb(uv_stream_t *handle, int status) { SocketWatcher *watcher = handle->data; CREATE_EVENT(watcher->events, connection_event, 2, watcher, - (void *)(uintptr_t)status); + (void *)(uintptr_t)status); } static void close_cb(uv_handle_t *handle) @@ -203,9 +201,8 @@ static void connect_cb(uv_connect_t *req, int status) } } -bool socket_connect(Loop *loop, Stream *stream, - bool is_tcp, const char *address, - int timeout, const char **error) +bool socket_connect(Loop *loop, Stream *stream, bool is_tcp, const char *address, int timeout, + const char **error) { bool success = false; int status; @@ -243,7 +240,6 @@ tcp_retry: uv_tcp_nodelay(tcp, true); uv_tcp_connect(&req, tcp, addrinfo->ai_addr, connect_cb); uv_stream = (uv_stream_t *)tcp; - } else { uv_pipe_t *pipe = &stream->uv.pipe; uv_pipe_init(&loop->uv, pipe, 0); diff --git a/src/nvim/event/stream.c b/src/nvim/event/stream.c index a8ded66ea5..8569b92d56 100644 --- a/src/nvim/event/stream.c +++ b/src/nvim/event/stream.c @@ -2,15 +2,14 @@ // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com #include <assert.h> -#include <stdio.h> #include <stdbool.h> - +#include <stdio.h> #include <uv.h> +#include "nvim/event/stream.h" #include "nvim/log.h" -#include "nvim/rbuffer.h" #include "nvim/macros.h" -#include "nvim/event/stream.h" +#include "nvim/rbuffer.h" #ifdef WIN32 # include "nvim/os/os_win_console.h" #endif @@ -77,7 +76,7 @@ void stream_init(Loop *loop, Stream *stream, int fd, uv_stream_t *uvstream) uv_pipe_open(&stream->uv.pipe, fd); stream->uvstream = STRUCT_CAST(uv_stream_t, &stream->uv.pipe); #ifdef WIN32 - } + } #endif } } diff --git a/src/nvim/event/time.c b/src/nvim/event/time.c index b7e30e392b..aa7b9cf2a1 100644 --- a/src/nvim/event/time.c +++ b/src/nvim/event/time.c @@ -2,7 +2,6 @@ // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com #include <stdint.h> - #include <uv.h> #include "nvim/event/loop.h" @@ -23,8 +22,7 @@ void time_watcher_init(Loop *loop, TimeWatcher *watcher, void *data) watcher->blockable = false; } -void time_watcher_start(TimeWatcher *watcher, time_cb cb, uint64_t timeout, - uint64_t repeat) +void time_watcher_start(TimeWatcher *watcher, time_cb cb, uint64_t timeout, uint64_t repeat) FUNC_ATTR_NONNULL_ALL { watcher->cb = cb; diff --git a/src/nvim/event/wstream.c b/src/nvim/event/wstream.c index 2baa667e7d..d81ffa5c15 100644 --- a/src/nvim/event/wstream.c +++ b/src/nvim/event/wstream.c @@ -2,17 +2,16 @@ // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com #include <assert.h> -#include <stdint.h> #include <stdbool.h> +#include <stdint.h> #include <stdlib.h> - #include <uv.h> -#include "nvim/log.h" #include "nvim/event/loop.h" #include "nvim/event/wstream.h" -#include "nvim/vim.h" +#include "nvim/log.h" #include "nvim/memory.h" +#include "nvim/vim.h" #define DEFAULT_MAXMEM 1024 * 1024 * 2000 @@ -117,10 +116,7 @@ err: /// @param cb Pointer to function that will be responsible for freeing /// the buffer data(passing 'free' will work as expected). /// @return The allocated WBuffer instance -WBuffer *wstream_new_buffer(char *data, - size_t size, - size_t refcount, - wbuffer_data_finalizer cb) +WBuffer *wstream_new_buffer(char *data, size_t size, size_t refcount, wbuffer_data_finalizer cb) FUNC_ATTR_NONNULL_ARG(1) { WBuffer *rv = xmalloc(sizeof(WBuffer)); |