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

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Sep 30, 2011
1 parent 24399c5 commit dedf51c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 12 deletions.
2 changes: 0 additions & 2 deletions include/uv-private/uv-unix.h
Expand Up @@ -100,8 +100,6 @@ typedef int uv_file;


#define UV_STREAM_PRIVATE_FIELDS \
uv_read_cb read_cb; \
uv_alloc_cb alloc_cb; \
uv_connect_t *connect_req; \
uv_shutdown_t *shutdown_req; \
ev_io read_watcher; \
Expand Down
2 changes: 0 additions & 2 deletions include/uv-private/uv-win.h
Expand Up @@ -132,8 +132,6 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);

#define UV_STREAM_PRIVATE_FIELDS \
unsigned int reqs_pending; \
uv_alloc_cb alloc_cb; \
uv_read_cb read_cb; \
uv_req_t read_req; \
union { \
struct { uv_stream_connection_fields }; \
Expand Down
5 changes: 4 additions & 1 deletion include/uv.h
Expand Up @@ -338,6 +338,9 @@ uv_buf_t uv_buf_init(char* base, size_t len);
#define UV_STREAM_FIELDS \
/* number of bytes queued for writing */ \
size_t write_queue_size; \
uv_alloc_cb alloc_cb; \
uv_read_cb read_cb; \
uv_read2_cb read2_cb; \
/* private */ \
UV_STREAM_PRIVATE_FIELDS

Expand Down Expand Up @@ -425,8 +428,8 @@ int uv_write2(uv_write_t* req, uv_stream_t* handle, uv_buf_t bufs[], int bufcnt,
struct uv_write_s {
UV_REQ_FIELDS
uv_write_cb cb;
uv_stream_t* handle;
uv_stream_t* send_handle;
uv_stream_t* handle;
UV_WRITE_PRIVATE_FIELDS
};

Expand Down
16 changes: 15 additions & 1 deletion src/unix/stream.c
Expand Up @@ -355,6 +355,8 @@ static void uv__write(uv_stream_t* stream) {
struct cmsghdr *cmsg;
int fd_to_send = req->send_handle->fd;

assert(fd_to_send >= 0);

msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_iov = iov;
Expand Down Expand Up @@ -778,7 +780,8 @@ int uv_write(uv_write_t* req, uv_stream_t* stream, uv_buf_t bufs[], int bufcnt,
}


int uv_read_start(uv_stream_t* stream, uv_alloc_cb alloc_cb, uv_read_cb read_cb) {
int uv_read_start(uv_stream_t* stream, uv_alloc_cb alloc_cb,
uv_read_cb read_cb) {
assert(stream->type == UV_TCP || stream->type == UV_NAMED_PIPE ||
stream->type == UV_TTY);

Expand Down Expand Up @@ -810,13 +813,24 @@ int uv_read_start(uv_stream_t* stream, uv_alloc_cb alloc_cb, uv_read_cb read_cb)
}


int uv_read2_start(uv_stream_t* stream, uv_alloc_cb alloc_cb,
uv_read2_cb read_cb) {
int r;
r = uv_read_start(stream, alloc_cb, NULL);
assert(stream->read_cb == NULL);
stream->read2_cb = read_cb;
return r;
}


int uv_read_stop(uv_stream_t* stream) {
uv_tcp_t* tcp = (uv_tcp_t*)stream;

((uv_handle_t*)tcp)->flags &= ~UV_READING;

ev_io_stop(tcp->loop->ev, &tcp->read_watcher);
tcp->read_cb = NULL;
tcp->read2_cb = NULL;
tcp->alloc_cb = NULL;
return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion test/run-tests.c
Expand Up @@ -83,7 +83,8 @@ static int ipc_helper() {
ASSERT(r == 0);

buf = uv_buf_init("hello\n", 6);
r = uv_write(&write_req, (uv_stream_t*)&channel, &buf, 1, NULL);
r = uv_write2(&write_req, (uv_stream_t*)&channel, &buf, 1,
(uv_stream_t*)&server, NULL);
ASSERT(r == 0);

r = uv_run(uv_default_loop());
Expand Down
12 changes: 7 additions & 5 deletions test/test-ipc.c
Expand Up @@ -49,17 +49,19 @@ static uv_buf_t on_alloc(uv_handle_t* handle, size_t suggested_size) {
}


static void on_read(uv_stream_t* pipe, ssize_t nread, uv_buf_t buf) {
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, pipe, &outbuf, 1, NULL);
r = uv_write(&write_req, (uv_stream_t*)pipe, &outbuf, 1, NULL);
ASSERT(r == 0);

fprintf(stderr, "got %d bytes\n", (int)nread);
ASSERT(pending == UV_TCP);
}

if (buf.base) {
Expand Down Expand Up @@ -92,7 +94,7 @@ TEST_IMPL(ipc) {
r = uv_spawn(uv_default_loop(), &process, options);
ASSERT(r == 0);

uv_read_start((uv_stream_t*)&channel, on_alloc, on_read);
uv_read2_start((uv_stream_t*)&channel, on_alloc, on_read);

r = uv_run(uv_default_loop());
ASSERT(r == 0);
Expand Down

0 comments on commit dedf51c

Please sign in to comment.