Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

make test-ipc accept the pending tcp server

  • Loading branch information...
Igor Zinkovsky
Igor Zinkovsky committed Oct 3, 2011
1 parent dedf51c commit 2d826fe1bcdb0dfd5f04fd68291e013ff4254d41
Showing with 37 additions and 12 deletions.
  1. +35 −11 test/test-ipc.c
  2. +1 −1 test/test-spawn.c
  3. +1 −0 uv.gyp
@@ -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");
@@ -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);
}


@@ -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;
}
@@ -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. */
1 uv.gyp
@@ -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',

0 comments on commit 2d826fe

Please sign in to comment.
You can’t perform that action at this time.