aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/os')
-rw-r--r--src/nvim/os/input.c29
-rw-r--r--src/nvim/os/shell.c25
-rw-r--r--src/nvim/os/signal.c11
-rw-r--r--src/nvim/os/time.c2
4 files changed, 44 insertions, 23 deletions
diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c
index b0e0f57e60..09f162f79d 100644
--- a/src/nvim/os/input.c
+++ b/src/nvim/os/input.c
@@ -33,6 +33,7 @@ static Stream read_stream = {.closed = true};
static RBuffer *input_buffer = NULL;
static bool input_eof = false;
static int global_fd = 0;
+static int events_enabled = 0;
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "os/input.c.generated.h"
@@ -110,8 +111,8 @@ int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt)
return (int)rbuffer_read(input_buffer, (char *)buf, (size_t)maxlen);
}
- // If there are deferred events, return the keys directly
- if (loop_has_deferred_events(&loop)) {
+ // If there are events, return the keys directly
+ if (pending_events()) {
return push_event_key(buf, maxlen);
}
@@ -131,11 +132,21 @@ bool os_char_avail(void)
// Check for CTRL-C typed by reading all available characters.
void os_breakcheck(void)
{
- if (!disable_breakcheck && !got_int) {
+ if (!got_int) {
loop_poll_events(&loop, 0);
}
}
+void input_enable_events(void)
+{
+ events_enabled++;
+}
+
+void input_disable_events(void)
+{
+ events_enabled--;
+}
+
/// Test whether a file descriptor refers to a terminal.
///
/// @param fd File descriptor.
@@ -281,7 +292,7 @@ static bool input_poll(int ms)
prof_inchar_enter();
}
- LOOP_POLL_EVENTS_UNTIL(&loop, ms, input_ready() || input_eof);
+ LOOP_PROCESS_EVENTS_UNTIL(&loop, NULL, ms, input_ready() || input_eof);
if (do_profiling == PROF_YES && ms) {
prof_inchar_exit();
@@ -305,7 +316,8 @@ static InbufPollResult inbuf_poll(int ms)
return input_eof ? kInputEof : kInputNone;
}
-static void read_cb(Stream *stream, RBuffer *buf, void *data, bool at_eof)
+static void read_cb(Stream *stream, RBuffer *buf, size_t c, void *data,
+ bool at_eof)
{
if (at_eof) {
input_eof = true;
@@ -358,7 +370,7 @@ static bool input_ready(void)
{
return typebuf_was_filled || // API call filled typeahead
rbuffer_size(input_buffer) || // Input buffer filled
- loop_has_deferred_events(&loop); // Events must be processed
+ pending_events(); // Events must be processed
}
// Exit because of an input read error.
@@ -369,3 +381,8 @@ static void read_error_exit(void)
STRCPY(IObuff, _("Vim: Error reading input, exiting...\n"));
preserve_exit();
}
+
+static bool pending_events(void)
+{
+ return events_enabled && !queue_empty(loop.events);
+}
diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c
index b9c5db4261..2d97c4bf4f 100644
--- a/src/nvim/os/shell.c
+++ b/src/nvim/os/shell.c
@@ -205,13 +205,15 @@ static int do_os_system(char **argv,
xstrlcpy(prog, argv[0], MAXPATHL);
Stream in, out, err;
- UvProcess uvproc = uv_process_init(&buf);
+ UvProcess uvproc = uv_process_init(&loop, &buf);
Process *proc = &uvproc.process;
+ Queue *events = queue_new_child(loop.events);
+ proc->events = events;
proc->argv = argv;
proc->in = input != NULL ? &in : NULL;
proc->out = &out;
proc->err = &err;
- if (!process_spawn(&loop, proc)) {
+ if (!process_spawn(proc)) {
loop_poll_events(&loop, 0);
// Failed, probably due to `sh` not being executable
if (!silent) {
@@ -219,14 +221,22 @@ static int do_os_system(char **argv,
msg_outtrans((char_u *)prog);
msg_putchar('\n');
}
+ queue_free(events);
return -1;
}
+ // We want to deal with stream events as fast a possible while queueing
+ // process events, so reset everything to NULL. It prevents closing the
+ // streams while there's still data in the OS buffer(due to the process
+ // exiting before all data is read).
if (input != NULL) {
+ proc->in->events = NULL;
wstream_init(proc->in, 0);
}
+ proc->out->events = NULL;
rstream_init(proc->out, 0);
rstream_start(proc->out, data_cb);
+ proc->err->events = NULL;
rstream_init(proc->err, 0);
rstream_start(proc->err, data_cb);
@@ -247,7 +257,7 @@ static int do_os_system(char **argv,
// the UI
ui_busy_start();
ui_flush();
- int status = process_wait(proc, -1);
+ int status = process_wait(proc, -1, NULL);
ui_busy_stop();
// prepare the out parameters if requested
@@ -267,6 +277,9 @@ static int do_os_system(char **argv,
}
}
+ assert(queue_empty(events));
+ queue_free(events);
+
return status;
}
@@ -285,7 +298,8 @@ static void dynamic_buffer_ensure(DynamicBuffer *buf, size_t desired)
buf->data = xrealloc(buf->data, buf->cap);
}
-static void system_data_cb(Stream *stream, RBuffer *buf, void *data, bool eof)
+static void system_data_cb(Stream *stream, RBuffer *buf, size_t count,
+ void *data, bool eof)
{
DynamicBuffer *dbuf = data;
@@ -295,7 +309,8 @@ static void system_data_cb(Stream *stream, RBuffer *buf, void *data, bool eof)
dbuf->len += nread;
}
-static void out_data_cb(Stream *stream, RBuffer *buf, void *data, bool eof)
+static void out_data_cb(Stream *stream, RBuffer *buf, size_t count, void *data,
+ bool eof)
{
size_t cnt;
char *ptr = rbuffer_read_ptr(buf, &cnt);
diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c
index 6de3435c4c..7158721433 100644
--- a/src/nvim/os/signal.c
+++ b/src/nvim/os/signal.c
@@ -115,16 +115,6 @@ static void deadly_signal(int signum)
static void on_signal(SignalWatcher *handle, int signum, void *data)
{
assert(signum >= 0);
- loop_push_event(&loop, (Event) {
- .handler = on_signal_event,
- .data = (void *)(uintptr_t)signum
- }, false);
-}
-
-static void on_signal_event(Event event)
-{
- int signum = (int)(uintptr_t)event.data;
-
switch (signum) {
#ifdef SIGPWR
case SIGPWR:
@@ -148,4 +138,3 @@ static void on_signal_event(Event event)
break;
}
}
-
diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c
index 6b5d4359db..ee17938afc 100644
--- a/src/nvim/os/time.c
+++ b/src/nvim/os/time.c
@@ -43,7 +43,7 @@ void os_delay(uint64_t milliseconds, bool ignoreinput)
if (milliseconds > INT_MAX) {
milliseconds = INT_MAX;
}
- LOOP_POLL_EVENTS_UNTIL(&loop, (int)milliseconds, got_int);
+ LOOP_PROCESS_EVENTS_UNTIL(&loop, NULL, (int)milliseconds, got_int);
} else {
os_microdelay(milliseconds * 1000);
}