Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
make test-ipc accept the pending tcp server
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Zinkovsky committed Oct 3, 2011
1 parent dedf51c commit 2d826fe
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
46 changes: 35 additions & 11 deletions test/test-ipc.c
Expand Up @@ -29,11 +29,18 @@ static char exepath[1024];
static size_t exepath_size = 1024;
static char* args[3];
static uv_pipe_t channel;
static uv_tcp_t tcp_server;

static int exit_cb_called;
static int read2_cb_called;

static uv_write_t write_req;

static void ipc_on_connection(uv_stream_t* server, int status) {
ASSERT(status == 0);
ASSERT((uv_stream_t*)&tcp_server == server);
}


static void exit_cb(uv_process_t* process, int exit_status, int term_signal) {
printf("exit_cb\n");
Expand All @@ -53,20 +60,36 @@ static void on_read(uv_pipe_t* pipe, ssize_t nread, uv_buf_t buf,
uv_handle_type pending) {
int r;
uv_buf_t outbuf;
/* listen on the handle provided.... */

if (nread) {
fprintf(stderr, "got %d bytes\n", (int)nread);

outbuf = uv_buf_init("world\n", 6);
r = uv_write(&write_req, (uv_stream_t*)pipe, &outbuf, 1, NULL);
ASSERT(r == 0);
ASSERT(pending == UV_TCP);
}

if (buf.base) {
if (nread == 0) {
/* Everything OK, but nothing read. */
free(buf.base);
return;
}

ASSERT(nread > 0 && buf.base && pending != UV_UNKNOWN_HANDLE);
read2_cb_called++;

/* Accept the pending TCP server, and start listening on it. */
ASSERT(pending == UV_TCP);
r = uv_tcp_init(uv_default_loop(), &tcp_server);
ASSERT(r == 0);

r = uv_accept((uv_stream_t*)pipe, (uv_stream_t*)&tcp_server);
ASSERT(r == 0);

r = uv_listen((uv_stream_t*)&tcp_server, 12, ipc_on_connection);
ASSERT(r == 0);

/* Make sure that the expected data is correctly multiplexed. */
ASSERT(memcmp("hello\n", buf.base, buf.len) == 0);
fprintf(stderr, "got %d bytes\n", (int)nread);

outbuf = uv_buf_init("world\n", 6);
r = uv_write(&write_req, (uv_stream_t*)pipe, &outbuf, 1, NULL);
ASSERT(r == 0);

free(buf.base);
}


Expand Down Expand Up @@ -99,6 +122,7 @@ TEST_IMPL(ipc) {
r = uv_run(uv_default_loop());
ASSERT(r == 0);

ASSERT(read2_cb_called == 1);
ASSERT(exit_cb_called == 1);
return 0;
}
2 changes: 1 addition & 1 deletion test/test-spawn.c
Expand Up @@ -229,7 +229,7 @@ TEST_IMPL(spawn_detect_pipe_name_collisions_on_windows) {

init_process_options("spawn_helper2", exit_cb);

uv_pipe_init(uv_default_loop(), &out);
uv_pipe_init(uv_default_loop(), &out, 0);
options.stdout_stream = &out;

/* Create a pipe that'll cause a collision. */
Expand Down
1 change: 1 addition & 0 deletions uv.gyp
Expand Up @@ -252,6 +252,7 @@
'test/test-getsockname.c',
'test/test-hrtime.c',
'test/test-idle.c',
'test/test-ipc.c',
'test/test-list.h',
'test/test-loop-handles.c',
'test/test-pass-always.c',
Expand Down

0 comments on commit 2d826fe

Please sign in to comment.