diff options
Diffstat (limited to 'src/nvim/os')
-rw-r--r-- | src/nvim/os/event.c | 2 | ||||
-rw-r--r-- | src/nvim/os/input.c | 13 | ||||
-rw-r--r-- | src/nvim/os/os.h | 1 | ||||
-rw-r--r-- | src/nvim/os/stream.c | 30 |
4 files changed, 42 insertions, 4 deletions
diff --git a/src/nvim/os/event.c b/src/nvim/os/event.c index 0560da1e2e..b0bd7ca55a 100644 --- a/src/nvim/os/event.c +++ b/src/nvim/os/event.c @@ -73,7 +73,7 @@ void event_teardown(void) // is required because the `process_events_from` above may call `event_push` // which will set the stop_flag to 1(uv_stop) uv_default_loop()->stop_flag = 0; - input_stop_stdin(); + input_stop(); channel_teardown(); job_teardown(); server_teardown(); diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index 486171b48a..74a5d3bc2e 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -1,6 +1,5 @@ #include <assert.h> #include <string.h> -#include <stdint.h> #include <stdbool.h> #include <uv.h> @@ -34,6 +33,7 @@ typedef enum { static RStream *read_stream = NULL; static RBuffer *read_buffer = NULL, *input_buffer = NULL; static bool input_eof = false; +static int global_fd = 0; #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/input.c.generated.h" @@ -46,19 +46,26 @@ void input_init(void) input_buffer = rbuffer_new(INPUT_BUFFER_SIZE + MAX_KEY_CODE_LEN); } -void input_start_stdin(int fd) +/// Gets the file from which input was gathered at startup. +int input_global_fd(void) +{ + return global_fd; +} + +void input_start(int fd) { if (read_stream) { return; } + global_fd = fd; read_buffer = rbuffer_new(READ_BUFFER_SIZE); read_stream = rstream_new(read_cb, read_buffer, NULL); rstream_set_file(read_stream, fd); rstream_start(read_stream); } -void input_stop_stdin(void) +void input_stop(void) { if (!read_stream) { return; diff --git a/src/nvim/os/os.h b/src/nvim/os/os.h index 69bd1ff4fd..3dd099890c 100644 --- a/src/nvim/os/os.h +++ b/src/nvim/os/os.h @@ -12,6 +12,7 @@ # include "os/mem.h.generated.h" # include "os/env.h.generated.h" # include "os/users.h.generated.h" +# include "os/stream.h.generated.h" #endif #endif // NVIM_OS_OS_H diff --git a/src/nvim/os/stream.c b/src/nvim/os/stream.c new file mode 100644 index 0000000000..0c448872c3 --- /dev/null +++ b/src/nvim/os/stream.c @@ -0,0 +1,30 @@ +// Functions for working with stdio streams (as opposed to RStream/WStream). + +#include <stdio.h> +#include <stdbool.h> + +#include <uv.h> + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/stream.c.generated.h" +#endif + +/// Sets the stream associated with `fd` to "blocking" mode. +/// +/// @return `0` on success, or `-errno` on failure. +int stream_set_blocking(int fd, bool blocking) +{ + // Private loop to avoid conflict with existing watcher(s): + // uv__io_stop: Assertion `loop->watchers[w->fd] == w' failed. + uv_loop_t loop; + uv_pipe_t stream; + uv_loop_init(&loop); + uv_pipe_init(&loop, &stream, 0); + uv_pipe_open(&stream, fd); + int retval = uv_stream_set_blocking((uv_stream_t *)&stream, blocking); + uv_close((uv_handle_t *)&stream, NULL); + uv_run(&loop, UV_RUN_NOWAIT); // not necessary, but couldn't hurt. + uv_loop_close(&loop); + return retval; +} + |