aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2017-08-27 11:59:33 +0200
committerBjörn Linse <bjorn.linse@gmail.com>2017-11-24 14:50:00 +0100
commit5215e3205a07b85e4e4cf1f8a8ca6be2b9556459 (patch)
tree515ccc2d01935465edd71f1d66f526be7dc66cfc /src/nvim/os
parent3717e2157f2d45ce23dbe4ac03085fea2d956dc4 (diff)
downloadrneovim-5215e3205a07b85e4e4cf1f8a8ca6be2b9556459.tar.gz
rneovim-5215e3205a07b85e4e4cf1f8a8ca6be2b9556459.tar.bz2
rneovim-5215e3205a07b85e4e4cf1f8a8ca6be2b9556459.zip
channels: refactor
Diffstat (limited to 'src/nvim/os')
-rw-r--r--src/nvim/os/pty_process_unix.c10
-rw-r--r--src/nvim/os/pty_process_win.c12
-rw-r--r--src/nvim/os/shell.c26
3 files changed, 22 insertions, 26 deletions
diff --git a/src/nvim/os/pty_process_unix.c b/src/nvim/os/pty_process_unix.c
index ee3ab96a83..e39f837c1a 100644
--- a/src/nvim/os/pty_process_unix.c
+++ b/src/nvim/os/pty_process_unix.c
@@ -47,7 +47,7 @@ int pty_process_spawn(PtyProcess *ptyproc)
int status = 0; // zero or negative error code (libuv convention)
Process *proc = (Process *)ptyproc;
- assert(!proc->err);
+ assert(proc->err.closed);
uv_signal_start(&proc->loop->children_watcher, chld_handler, SIGCHLD);
ptyproc->winsize = (struct winsize){ ptyproc->height, ptyproc->width, 0, 0 };
uv_disable_stdio_inheritance();
@@ -83,12 +83,12 @@ int pty_process_spawn(PtyProcess *ptyproc)
goto error;
}
- if (proc->in
- && (status = set_duplicating_descriptor(master, &proc->in->uv.pipe))) {
+ if (!proc->in.closed
+ && (status = set_duplicating_descriptor(master, &proc->in.uv.pipe))) {
goto error;
}
- if (proc->out
- && (status = set_duplicating_descriptor(master, &proc->out->uv.pipe))) {
+ if (!proc->out.closed
+ && (status = set_duplicating_descriptor(master, &proc->out.uv.pipe))) {
goto error;
}
diff --git a/src/nvim/os/pty_process_win.c b/src/nvim/os/pty_process_win.c
index ef8a699c56..3c4839a076 100644
--- a/src/nvim/os/pty_process_win.c
+++ b/src/nvim/os/pty_process_win.c
@@ -44,7 +44,7 @@ int pty_process_spawn(PtyProcess *ptyproc)
wchar_t *cwd = NULL;
const char *emsg = NULL;
- assert(!proc->err);
+ assert(proc->err.closed);
cfg = winpty_config_new(WINPTY_FLAG_ALLOW_CURPROC_DESKTOP_CREATION, &err);
if (cfg == NULL) {
@@ -71,20 +71,20 @@ int pty_process_spawn(PtyProcess *ptyproc)
goto cleanup;
}
- if (proc->in != NULL) {
+ if (!proc->in.closed) {
in_req = xmalloc(sizeof(uv_connect_t));
uv_pipe_connect(
in_req,
- &proc->in->uv.pipe,
+ &proc->in.uv.pipe,
in_name,
pty_process_connect_cb);
}
- if (proc->out != NULL) {
+ if (!proc->out.closed) {
out_req = xmalloc(sizeof(uv_connect_t));
uv_pipe_connect(
out_req,
- &proc->out->uv.pipe,
+ &proc->out.uv.pipe,
out_name,
pty_process_connect_cb);
}
@@ -228,7 +228,7 @@ static void wait_eof_timer_cb(uv_timer_t *wait_eof_timer)
PtyProcess *ptyproc = wait_eof_timer->data;
Process *proc = (Process *)ptyproc;
- if (!proc->out || !uv_is_readable(proc->out->uvstream)) {
+ if (proc->out.closed || !uv_is_readable(proc->out.uvstream)) {
uv_timer_stop(&ptyproc->wait_eof_timer);
pty_process_finish2(ptyproc);
}
diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c
index 32e9a70e57..f54fe412ba 100644
--- a/src/nvim/os/shell.c
+++ b/src/nvim/os/shell.c
@@ -207,16 +207,12 @@ static int do_os_system(char **argv,
char prog[MAXPATHL];
xstrlcpy(prog, argv[0], MAXPATHL);
- Stream in, out, err;
LibuvProcess uvproc = libuv_process_init(&main_loop, &buf);
Process *proc = &uvproc.process;
MultiQueue *events = multiqueue_new_child(main_loop.events);
proc->events = events;
proc->argv = argv;
- proc->in = input != NULL ? &in : NULL;
- proc->out = &out;
- proc->err = &err;
- int status = process_spawn(proc);
+ int status = process_spawn(proc, input != NULL, true, true);
if (status) {
loop_poll_events(&main_loop, 0);
// Failed, probably 'shell' is not executable.
@@ -236,27 +232,27 @@ static int do_os_system(char **argv,
// 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->in.events = NULL;
+ wstream_init(&proc->in, 0);
}
- proc->out->events = NULL;
- rstream_init(proc->out, 0);
- rstream_start(proc->out, data_cb, &buf);
- proc->err->events = NULL;
- rstream_init(proc->err, 0);
- rstream_start(proc->err, data_cb, &buf);
+ proc->out.events = NULL;
+ rstream_init(&proc->out, 0);
+ rstream_start(&proc->out, data_cb, &buf);
+ proc->err.events = NULL;
+ rstream_init(&proc->err, 0);
+ rstream_start(&proc->err, data_cb, &buf);
// write the input, if any
if (input) {
WBuffer *input_buffer = wstream_new_buffer((char *) input, len, 1, NULL);
- if (!wstream_write(&in, input_buffer)) {
+ if (!wstream_write(&proc->in, input_buffer)) {
// couldn't write, stop the process and tell the user about it
process_stop(proc);
return -1;
}
// close the input stream after everything is written
- wstream_set_write_cb(&in, shell_write_cb, NULL);
+ wstream_set_write_cb(&proc->in, shell_write_cb, NULL);
}
// Invoke busy_start here so LOOP_PROCESS_EVENTS_UNTIL will not change the