diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2015-05-27 09:34:40 -0400 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2015-05-27 09:34:40 -0400 |
commit | 3dd166b20387607d73fee01507e7c9ddcfa9bcd4 (patch) | |
tree | 5647ea22f1e7fd35b56df9893ebfd5717481d857 /src/nvim/os/stream.c | |
parent | 5a9ad68b258f33ebd7fa0a5da47b308f50f1e5e7 (diff) | |
parent | b2c400b3f2354b2765e1d6f3b5ce4b11f2ab75a3 (diff) | |
download | rneovim-3dd166b20387607d73fee01507e7c9ddcfa9bcd4.tar.gz rneovim-3dd166b20387607d73fee01507e7c9ddcfa9bcd4.tar.bz2 rneovim-3dd166b20387607d73fee01507e7c9ddcfa9bcd4.zip |
Merge #2598 'set stdin as "blocking" on exit'
Diffstat (limited to 'src/nvim/os/stream.c')
-rw-r--r-- | src/nvim/os/stream.c | 30 |
1 files changed, 30 insertions, 0 deletions
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; +} + |