aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os/stream.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2015-05-25 14:13:18 -0400
committerJustin M. Keyes <justinkz@gmail.com>2015-05-27 09:34:04 -0400
commit4219b69145f13e95eadb5a666cb02b482bdd395b (patch)
tree5684a6cb585e60372d41144a4ae13eee8aaab710 /src/nvim/os/stream.c
parent8a782f1699e2a59a3f3e91f6d7c35a3312b82b41 (diff)
downloadrneovim-4219b69145f13e95eadb5a666cb02b482bdd395b.tar.gz
rneovim-4219b69145f13e95eadb5a666cb02b482bdd395b.tar.bz2
rneovim-4219b69145f13e95eadb5a666cb02b482bdd395b.zip
input: stream_set_blocking(): libuv impl
- Create a private libuv loop instead of re-using uv_default_loop(), to avoid conflict[1] with existing watcher(s) on the fd. - Expose the global "input" fd as a getter instead of a mutable global. [1] .deps/build/src/libuv/src/unix/core.c:833: uv__io_stop: Assertion `loop->watchers[w->fd] == w' failed.
Diffstat (limited to 'src/nvim/os/stream.c')
-rw-r--r--src/nvim/os/stream.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/nvim/os/stream.c b/src/nvim/os/stream.c
index 35cb41081d..0c448872c3 100644
--- a/src/nvim/os/stream.c
+++ b/src/nvim/os/stream.c
@@ -14,13 +14,17 @@
/// @return `0` on success, or `-errno` on failure.
int stream_set_blocking(int fd, bool blocking)
{
- int flags = fcntl(fd, F_GETFL, 0);
- int err = 0;
- if (!blocking && !(flags & O_NONBLOCK)) {
- err = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
- } else if (blocking && (flags & O_NONBLOCK)) {
- err = fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
- }
- return err == -1 ? -errno : 0;
+ // 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;
}