Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

WIP

  • Loading branch information...
commit c993af638b77317c4eb547184159c424e8a2e1f6 1 parent 1154166
@felixge felixge authored piscisaureus committed
Showing with 50 additions and 15 deletions.
  1. +7 −3 src/unix/process.c
  2. +26 −6 test/run-tests.c
  3. +17 −6 test/test-spawn-sync.c
View
10 src/unix/process.c
@@ -481,11 +481,15 @@ int uv_spawn_sync(uv_loop_t* loop, uv_spawn_sync_t* spawn) {
}
if (spawn->stdin_buf && FD_ISSET(stdin_pipe[1], &write_fds) && spawn->stdin_written < spawn->stdin_size) {
+ fprintf(stderr, "write!\n");
int written = write(stdin_pipe[1], spawn->stdin_buf + spawn->stdin_written, spawn->stdin_size - spawn->stdin_written);
+ fprintf(stderr, "wrote: %i\n", written);
- if (written == -1 && errno != EINTR) {
- uv_err_new(loop, errno);
- goto error;
+ if (written == -1) {
+ if (errno != EINTR) {
+ uv_err_new(loop, errno);
+ goto error;
+ }
} else {
spawn->stdin_written += written;
}
View
32 test/run-tests.c
@@ -22,6 +22,7 @@
#include <stdio.h>
#include <string.h>
+#include <unistd.h>
#include "runner.h"
#include "task.h"
@@ -72,14 +73,33 @@ static int maybe_run_test(int argc, char **argv) {
}
if (strcmp(argv[1], "spawn_helper_stdin_stream") == 0) {
- char buffer[4];
- fgets(buffer, sizeof(buffer), stdin);
- fputs(buffer, stdout);
+ int nfds;
+ nfds = STDIN_FILENO + 1;
+ fd_set fds;
- uv_sleep(1000);
+ struct timeval select_timeout;
+ select_timeout.tv_sec = 1;
+ select_timeout.tv_usec = 0;
- fgets(buffer, sizeof(buffer), stdin);
- fputs(buffer, stdout);
+
+ while(1) {
+ int r;
+
+ FD_ZERO(&fds);
+ FD_SET(STDIN_FILENO, &fds);
+
+ r = select(nfds, &fds, NULL, NULL, &select_timeout);
+
+ if (FD_ISSET(STDIN_FILENO, &fds)) {
+ char buf[1024];
+ int bytes_read = read(STDIN_FILENO, buf, sizeof(1024));
+ if (bytes_read > 0) {
+ write(STDIN_FILENO, buf, bytes_read);
+ }
+ }
+ }
+ /*fgets(buffer, sizeof(buffer), stdin);*/
+ /*fputs(buffer, stdout);*/
return 1;
}
View
23 test/test-spawn-sync.c
@@ -54,13 +54,22 @@ void debug(int r) {
fprintf(stderr, "----------------------------------------\n");
fprintf(stderr, "r: %i\n", r);
fprintf(stderr, "spawn.pid: %i\n", spawn.pid);
+
fprintf(stderr, "spawn.stdout_read: %i\n", spawn.stdout_read);
fprintf(stderr, "spawn.stdout_size: %i\n", spawn.stdout_size);
- fprintf(stderr, "spawn.stdout: %s\n", spawn.stdout_buf);
+ if (spawn.stdout_size < 1024) {
+ fprintf(stderr, "spawn.stdout: %s\n", spawn.stdout_buf);
+ }
+
fprintf(stderr, "spawn.stderr_read: %i\n", spawn.stderr_read);
fprintf(stderr, "spawn.stderr_size: %i\n", spawn.stderr_size);
- fprintf(stderr, "spawn.stderr: %s\n", spawn.stderr_buf);
+ if (spawn.stderr_size < 1024) {
+ fprintf(stderr, "spawn.stderr: %s\n", spawn.stderr_buf);
+ }
+
+ fprintf(stderr, "spawn.stdin_size: %i\n", spawn.stdin_size);
fprintf(stderr, "spawn.stdin_written: %i\n", spawn.stdin_written);
+
fprintf(stderr, "spawn.exit_timeout: %i\n", spawn.exit_timeout);
fprintf(stderr, "spawn.exit_code: %i\n", spawn.exit_code);
fprintf(stderr, "spawn.exit_signal: %i\n", spawn.exit_signal);
@@ -245,15 +254,17 @@ TEST_IMPL(spawn_sync_stdin_stream) {
init_process_options("spawn_helper_stdin_stream");
- spawn.stdin_buf = "stdin\n";
- spawn.stdin_size = strlen(spawn.stdin_buf);
+ spawn.stdin_size = 1024 * 1024 * 1024;
+ spawn.stdin_buf = malloc(spawn.stdin_size);
+ spawn.stdout_size = spawn.stdin_size;
+ spawn.stdout_buf = malloc(spawn.stdout_size);
r = uv_spawn_sync(uv_default_loop(), &spawn);
debug(r);
ASSERT(r == 0);
- ASSERT(strcmp(spawn.stdout_buf, spawn.stdin_buf) == 0);
- ASSERT(spawn.stdout_read == strlen(spawn.stdin_buf));
+ /*ASSERT(strcmp(spawn.stdout_buf, spawn.stdin_buf) == 0);*/
+ ASSERT(spawn.stdout_read == spawn.stdin_size);
return 0;
}
Please sign in to comment.
Something went wrong with that request. Please try again.