include: uv_read{2}_cb now takes const uv_buf_t*

Passing or returning structs as values makes life hard for people that
work with libuv through a foreign function interface. Switch to a
pointer-based approach.

Fixes #684.
This commit is contained in:
Ben Noordhuis 2013-08-31 02:15:08 +02:00
parent 3fb6612233
commit b7d027c3a8
28 changed files with 177 additions and 148 deletions

View File

@ -361,18 +361,22 @@ typedef void (*uv_alloc_cb)(uv_handle_t* handle,
* Trying to read from the stream again is undefined. * Trying to read from the stream again is undefined.
* *
* The callee is responsible for freeing the buffer, libuv does not reuse it. * The callee is responsible for freeing the buffer, libuv does not reuse it.
* The buffer may be a null buffer (where buf.base=NULL and buf.len=0) on EOF * The buffer may be a null buffer (where buf->base=NULL and buf->len=0) on
* or error. * EOF or error.
*/ */
typedef void (*uv_read_cb)(uv_stream_t* stream, ssize_t nread, uv_buf_t buf); typedef void (*uv_read_cb)(uv_stream_t* stream,
ssize_t nread,
const uv_buf_t* buf);
/* /*
* Just like the uv_read_cb except that if the pending parameter is true * Just like the uv_read_cb except that if the pending parameter is true
* then you can use uv_accept() to pull the new handle into the process. * then you can use uv_accept() to pull the new handle into the process.
* If no handle is pending then pending will be UV_UNKNOWN_HANDLE. * If no handle is pending then pending will be UV_UNKNOWN_HANDLE.
*/ */
typedef void (*uv_read2_cb)(uv_pipe_t* pipe, ssize_t nread, uv_buf_t buf, typedef void (*uv_read2_cb)(uv_pipe_t* pipe,
uv_handle_type pending); ssize_t nread,
const uv_buf_t* buf,
uv_handle_type pending);
typedef void (*uv_write_cb)(uv_write_t* req, int status); typedef void (*uv_write_cb)(uv_write_t* req, int status);
typedef void (*uv_connect_cb)(uv_connect_t* req, int status); typedef void (*uv_connect_cb)(uv_connect_t* req, int status);

View File

@ -938,7 +938,7 @@ static uv_handle_type uv__handle_type(int fd) {
static void uv__stream_read_cb(uv_stream_t* stream, static void uv__stream_read_cb(uv_stream_t* stream,
int status, int status,
uv_buf_t buf, const uv_buf_t* buf,
uv_handle_type type) { uv_handle_type type) {
if (stream->read_cb != NULL) if (stream->read_cb != NULL)
stream->read_cb(stream, status, buf); stream->read_cb(stream, status, buf);
@ -947,7 +947,7 @@ static void uv__stream_read_cb(uv_stream_t* stream,
} }
static void uv__stream_eof(uv_stream_t* stream, uv_buf_t buf) { static void uv__stream_eof(uv_stream_t* stream, const uv_buf_t* buf) {
stream->flags |= UV_STREAM_READ_EOF; stream->flags |= UV_STREAM_READ_EOF;
uv__io_stop(stream->loop, &stream->io_watcher, UV__POLLIN); uv__io_stop(stream->loop, &stream->io_watcher, UV__POLLIN);
if (!uv__io_active(&stream->io_watcher, UV__POLLOUT)) if (!uv__io_active(&stream->io_watcher, UV__POLLOUT))
@ -982,7 +982,7 @@ static void uv__read(uv_stream_t* stream) {
stream->alloc_cb((uv_handle_t*)stream, 64 * 1024, &buf); stream->alloc_cb((uv_handle_t*)stream, 64 * 1024, &buf);
if (buf.len == 0) { if (buf.len == 0) {
/* User indicates it can't or won't handle the read. */ /* User indicates it can't or won't handle the read. */
uv__stream_read_cb(stream, UV_ENOBUFS, buf, UV_UNKNOWN_HANDLE); uv__stream_read_cb(stream, UV_ENOBUFS, &buf, UV_UNKNOWN_HANDLE);
return; return;
} }
@ -1019,23 +1019,23 @@ static void uv__read(uv_stream_t* stream) {
if (stream->flags & UV_STREAM_READING) { if (stream->flags & UV_STREAM_READING) {
uv__io_start(stream->loop, &stream->io_watcher, UV__POLLIN); uv__io_start(stream->loop, &stream->io_watcher, UV__POLLIN);
} }
uv__stream_read_cb(stream, 0, buf, UV_UNKNOWN_HANDLE); uv__stream_read_cb(stream, 0, &buf, UV_UNKNOWN_HANDLE);
} else { } else {
/* Error. User should call uv_close(). */ /* Error. User should call uv_close(). */
uv__stream_read_cb(stream, -errno, buf, UV_UNKNOWN_HANDLE); uv__stream_read_cb(stream, -errno, &buf, UV_UNKNOWN_HANDLE);
assert(!uv__io_active(&stream->io_watcher, UV__POLLIN) && assert(!uv__io_active(&stream->io_watcher, UV__POLLIN) &&
"stream->read_cb(status=-1) did not call uv_close()"); "stream->read_cb(status=-1) did not call uv_close()");
} }
return; return;
} else if (nread == 0) { } else if (nread == 0) {
uv__stream_eof(stream, buf); uv__stream_eof(stream, &buf);
return; return;
} else { } else {
/* Successful read */ /* Successful read */
ssize_t buflen = buf.len; ssize_t buflen = buf.len;
if (stream->read_cb) { if (stream->read_cb) {
stream->read_cb(stream, nread, buf); stream->read_cb(stream, nread, &buf);
} else { } else {
assert(stream->read2_cb); assert(stream->read2_cb);
@ -1070,10 +1070,12 @@ static void uv__read(uv_stream_t* stream) {
if (stream->accepted_fd >= 0) { if (stream->accepted_fd >= 0) {
stream->read2_cb((uv_pipe_t*)stream, nread, buf, stream->read2_cb((uv_pipe_t*) stream,
uv__handle_type(stream->accepted_fd)); nread,
&buf,
uv__handle_type(stream->accepted_fd));
} else { } else {
stream->read2_cb((uv_pipe_t*)stream, nread, buf, UV_UNKNOWN_HANDLE); stream->read2_cb((uv_pipe_t*) stream, nread, &buf, UV_UNKNOWN_HANDLE);
} }
} }
@ -1147,7 +1149,7 @@ static void uv__stream_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
(stream->flags & UV_STREAM_READ_PARTIAL) && (stream->flags & UV_STREAM_READ_PARTIAL) &&
!(stream->flags & UV_STREAM_READ_EOF)) { !(stream->flags & UV_STREAM_READ_EOF)) {
uv_buf_t buf = { NULL, 0 }; uv_buf_t buf = { NULL, 0 };
uv__stream_eof(stream, buf); uv__stream_eof(stream, &buf);
} }
if (uv__stream_fd(stream) == -1) if (uv__stream_fd(stream) == -1)

View File

@ -1296,9 +1296,9 @@ static void uv_pipe_read_eof(uv_loop_t* loop, uv_pipe_t* handle,
uv_read_stop((uv_stream_t*) handle); uv_read_stop((uv_stream_t*) handle);
if (handle->read2_cb) { if (handle->read2_cb) {
handle->read2_cb(handle, UV_EOF, uv_null_buf_, UV_UNKNOWN_HANDLE); handle->read2_cb(handle, UV_EOF, &uv_null_buf_, UV_UNKNOWN_HANDLE);
} else { } else {
handle->read_cb((uv_stream_t*) handle, UV_EOF, uv_null_buf_); handle->read_cb((uv_stream_t*) handle, UV_EOF, &uv_null_buf_);
} }
} }
@ -1314,10 +1314,10 @@ static void uv_pipe_read_error(uv_loop_t* loop, uv_pipe_t* handle, int error,
if (handle->read2_cb) { if (handle->read2_cb) {
handle->read2_cb(handle, handle->read2_cb(handle,
uv_translate_sys_error(error), uv_translate_sys_error(error),
buf, &buf,
UV_UNKNOWN_HANDLE); UV_UNKNOWN_HANDLE);
} else { } else {
handle->read_cb((uv_stream_t*)handle, uv_translate_sys_error(error), buf); handle->read_cb((uv_stream_t*)handle, uv_translate_sys_error(error), &buf);
} }
} }
@ -1432,9 +1432,9 @@ void uv_process_pipe_read_req(uv_loop_t* loop, uv_pipe_t* handle,
handle->alloc_cb((uv_handle_t*) handle, avail, &buf); handle->alloc_cb((uv_handle_t*) handle, avail, &buf);
if (buf.len == 0) { if (buf.len == 0) {
if (handle->read2_cb) { if (handle->read2_cb) {
handle->read2_cb(handle, UV_ENOBUFS, buf, UV_UNKNOWN_HANDLE); handle->read2_cb(handle, UV_ENOBUFS, &buf, UV_UNKNOWN_HANDLE);
} else if (handle->read_cb) { } else if (handle->read_cb) {
handle->read_cb((uv_stream_t*) handle, UV_ENOBUFS, buf); handle->read_cb((uv_stream_t*) handle, UV_ENOBUFS, &buf);
} }
break; break;
} }
@ -1451,10 +1451,10 @@ void uv_process_pipe_read_req(uv_loop_t* loop, uv_pipe_t* handle,
handle->remaining_ipc_rawdata_bytes = handle->remaining_ipc_rawdata_bytes =
handle->remaining_ipc_rawdata_bytes - bytes; handle->remaining_ipc_rawdata_bytes - bytes;
if (handle->read2_cb) { if (handle->read2_cb) {
handle->read2_cb(handle, bytes, buf, handle->read2_cb(handle, bytes, &buf,
handle->pending_ipc_info.socket_info ? UV_TCP : UV_UNKNOWN_HANDLE); handle->pending_ipc_info.socket_info ? UV_TCP : UV_UNKNOWN_HANDLE);
} else if (handle->read_cb) { } else if (handle->read_cb) {
handle->read_cb((uv_stream_t*)handle, bytes, buf); handle->read_cb((uv_stream_t*)handle, bytes, &buf);
} }
if (handle->pending_ipc_info.socket_info) { if (handle->pending_ipc_info.socket_info) {
@ -1462,7 +1462,7 @@ void uv_process_pipe_read_req(uv_loop_t* loop, uv_pipe_t* handle,
handle->pending_ipc_info.socket_info = NULL; handle->pending_ipc_info.socket_info = NULL;
} }
} else { } else {
handle->read_cb((uv_stream_t*)handle, bytes, buf); handle->read_cb((uv_stream_t*)handle, bytes, &buf);
} }
/* Read again only if bytes == buf.len */ /* Read again only if bytes == buf.len */

View File

@ -436,7 +436,7 @@ static void uv_tcp_queue_read(uv_loop_t* loop, uv_tcp_t* handle) {
handle->flags &= ~UV_HANDLE_ZERO_READ; handle->flags &= ~UV_HANDLE_ZERO_READ;
handle->alloc_cb((uv_handle_t*) handle, 65536, &handle->read_buffer); handle->alloc_cb((uv_handle_t*) handle, 65536, &handle->read_buffer);
if (handle->read_buffer.len == 0) { if (handle->read_buffer.len == 0) {
handle->read_cb((uv_stream_t*) handle, UV_ENOBUFS, handle->read_buffer); handle->read_cb((uv_stream_t*) handle, UV_ENOBUFS, &handle->read_buffer);
return; return;
} }
assert(handle->read_buffer.base != NULL); assert(handle->read_buffer.base != NULL);
@ -916,7 +916,7 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
handle->read_cb((uv_stream_t*)handle, handle->read_cb((uv_stream_t*)handle,
uv_translate_sys_error(err), uv_translate_sys_error(err),
buf); &buf);
} }
} else { } else {
if (!(handle->flags & UV_HANDLE_ZERO_READ)) { if (!(handle->flags & UV_HANDLE_ZERO_READ)) {
@ -925,7 +925,7 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
/* Successful read */ /* Successful read */
handle->read_cb((uv_stream_t*)handle, handle->read_cb((uv_stream_t*)handle,
req->overlapped.InternalHigh, req->overlapped.InternalHigh,
handle->read_buffer); &handle->read_buffer);
/* Read again only if bytes == buf.len */ /* Read again only if bytes == buf.len */
if (req->overlapped.InternalHigh < handle->read_buffer.len) { if (req->overlapped.InternalHigh < handle->read_buffer.len) {
goto done; goto done;
@ -940,7 +940,7 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
buf.base = 0; buf.base = 0;
buf.len = 0; buf.len = 0;
handle->read_cb((uv_stream_t*)handle, UV_EOF, handle->read_buffer); handle->read_cb((uv_stream_t*)handle, UV_EOF, &handle->read_buffer);
goto done; goto done;
} }
} }
@ -949,7 +949,7 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
while (handle->flags & UV_HANDLE_READING) { while (handle->flags & UV_HANDLE_READING) {
handle->alloc_cb((uv_handle_t*) handle, 65536, &buf); handle->alloc_cb((uv_handle_t*) handle, 65536, &buf);
if (buf.len == 0) { if (buf.len == 0) {
handle->read_cb(handle, UV_ENOBUFS, buf); handle->read_cb((uv_stream_t*) handle, UV_ENOBUFS, &buf);
break; break;
} }
assert(buf.base != NULL); assert(buf.base != NULL);
@ -964,7 +964,7 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
NULL) != SOCKET_ERROR) { NULL) != SOCKET_ERROR) {
if (bytes > 0) { if (bytes > 0) {
/* Successful read */ /* Successful read */
handle->read_cb((uv_stream_t*)handle, bytes, buf); handle->read_cb((uv_stream_t*)handle, bytes, &buf);
/* Read again only if bytes == buf.len */ /* Read again only if bytes == buf.len */
if (bytes < buf.len) { if (bytes < buf.len) {
break; break;
@ -974,14 +974,14 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
handle->flags &= ~(UV_HANDLE_READING | UV_HANDLE_READABLE); handle->flags &= ~(UV_HANDLE_READING | UV_HANDLE_READABLE);
DECREASE_ACTIVE_COUNT(loop, handle); DECREASE_ACTIVE_COUNT(loop, handle);
handle->read_cb((uv_stream_t*)handle, UV_EOF, buf); handle->read_cb((uv_stream_t*)handle, UV_EOF, &buf);
break; break;
} }
} else { } else {
err = WSAGetLastError(); err = WSAGetLastError();
if (err == WSAEWOULDBLOCK) { if (err == WSAEWOULDBLOCK) {
/* Read buffer was completely empty, report a 0-byte read. */ /* Read buffer was completely empty, report a 0-byte read. */
handle->read_cb((uv_stream_t*)handle, 0, buf); handle->read_cb((uv_stream_t*)handle, 0, &buf);
} else { } else {
/* Ouch! serious error. */ /* Ouch! serious error. */
handle->flags &= ~UV_HANDLE_READING; handle->flags &= ~UV_HANDLE_READING;
@ -995,7 +995,7 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
handle->read_cb((uv_stream_t*)handle, handle->read_cb((uv_stream_t*)handle,
uv_translate_sys_error(err), uv_translate_sys_error(err),
buf); &buf);
} }
break; break;
} }

View File

@ -349,7 +349,9 @@ static void uv_tty_queue_read_line(uv_loop_t* loop, uv_tty_t* handle) {
handle->alloc_cb((uv_handle_t*) handle, 8192, &handle->read_line_buffer); handle->alloc_cb((uv_handle_t*) handle, 8192, &handle->read_line_buffer);
if (handle->read_line_buffer.len == 0) { if (handle->read_line_buffer.len == 0) {
handle->read_cb(handle, UV_ENOBUFS, handle->read_line_buffer); handle->read_cb((uv_stream_t*) handle,
UV_ENOBUFS,
&handle->read_line_buffer);
return; return;
} }
assert(handle->read_line_buffer.base != NULL); assert(handle->read_line_buffer.base != NULL);
@ -486,7 +488,7 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
handle->flags &= ~UV_HANDLE_READING; handle->flags &= ~UV_HANDLE_READING;
handle->read_cb((uv_stream_t*)handle, handle->read_cb((uv_stream_t*)handle,
uv_translate_sys_error(GET_REQ_ERROR(req)), uv_translate_sys_error(GET_REQ_ERROR(req)),
uv_null_buf_); &uv_null_buf_);
} }
goto out; goto out;
} }
@ -497,7 +499,7 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
DECREASE_ACTIVE_COUNT(loop, handle); DECREASE_ACTIVE_COUNT(loop, handle);
handle->read_cb((uv_stream_t*)handle, handle->read_cb((uv_stream_t*)handle,
uv_translate_sys_error(GetLastError()), uv_translate_sys_error(GetLastError()),
uv_null_buf_); &uv_null_buf_);
goto out; goto out;
} }
@ -518,7 +520,7 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
DECREASE_ACTIVE_COUNT(loop, handle); DECREASE_ACTIVE_COUNT(loop, handle);
handle->read_cb((uv_stream_t*) handle, handle->read_cb((uv_stream_t*) handle,
uv_translate_sys_error(GetLastError()), uv_translate_sys_error(GetLastError()),
buf); &buf);
goto out; goto out;
} }
records_left--; records_left--;
@ -638,7 +640,7 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
DECREASE_ACTIVE_COUNT(loop, handle); DECREASE_ACTIVE_COUNT(loop, handle);
handle->read_cb((uv_stream_t*) handle, handle->read_cb((uv_stream_t*) handle,
uv_translate_sys_error(GetLastError()), uv_translate_sys_error(GetLastError()),
buf); &buf);
goto out; goto out;
} }
@ -686,7 +688,7 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
if (buf_used == 0) { if (buf_used == 0) {
handle->alloc_cb((uv_handle_t*) handle, 1024, &buf); handle->alloc_cb((uv_handle_t*) handle, 1024, &buf);
if (buf.len == 0) { if (buf.len == 0) {
handle->read_cb((uv_stream_t*) handle, UV_ENOBUFS, buf); handle->read_cb((uv_stream_t*) handle, UV_ENOBUFS, &buf);
goto out; goto out;
} }
assert(buf.base != NULL); assert(buf.base != NULL);
@ -696,7 +698,7 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
/* If the buffer is full, emit it */ /* If the buffer is full, emit it */
if (buf_used == buf.len) { if (buf_used == buf.len) {
handle->read_cb((uv_stream_t*) handle, buf_used, buf); handle->read_cb((uv_stream_t*) handle, buf_used, &buf);
buf = uv_null_buf_; buf = uv_null_buf_;
buf_used = 0; buf_used = 0;
} }
@ -717,7 +719,7 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
/* Send the buffer back to the user */ /* Send the buffer back to the user */
if (buf_used > 0) { if (buf_used > 0) {
handle->read_cb((uv_stream_t*) handle, buf_used, buf); handle->read_cb((uv_stream_t*) handle, buf_used, &buf);
} }
out: out:
@ -755,17 +757,17 @@ void uv_process_tty_read_line_req(uv_loop_t* loop, uv_tty_t* handle,
DECREASE_ACTIVE_COUNT(loop, handle); DECREASE_ACTIVE_COUNT(loop, handle);
handle->read_cb((uv_stream_t*) handle, handle->read_cb((uv_stream_t*) handle,
uv_translate_sys_error(GET_REQ_ERROR(req)), uv_translate_sys_error(GET_REQ_ERROR(req)),
buf); &buf);
} else { } else {
/* The read was cancelled, or whatever we don't care */ /* The read was cancelled, or whatever we don't care */
handle->read_cb((uv_stream_t*) handle, 0, buf); handle->read_cb((uv_stream_t*) handle, 0, &buf);
} }
} else { } else {
/* Read successful */ /* Read successful */
/* TODO: read unicode, convert to utf-8 */ /* TODO: read unicode, convert to utf-8 */
DWORD bytes = req->overlapped.InternalHigh; DWORD bytes = req->overlapped.InternalHigh;
handle->read_cb((uv_stream_t*) handle, bytes, buf); handle->read_cb((uv_stream_t*) handle, bytes, &buf);
} }
/* Wait for more input events. */ /* Wait for more input events. */

View File

@ -85,7 +85,7 @@ static void ipc_close_cb(uv_handle_t* handle);
static void ipc_connect_cb(uv_connect_t* req, int status); static void ipc_connect_cb(uv_connect_t* req, int status);
static void ipc_read2_cb(uv_pipe_t* ipc_pipe, static void ipc_read2_cb(uv_pipe_t* ipc_pipe,
ssize_t nread, ssize_t nread,
uv_buf_t buf, const uv_buf_t* buf,
uv_handle_type type); uv_handle_type type);
static void ipc_alloc_cb(uv_handle_t* handle, static void ipc_alloc_cb(uv_handle_t* handle,
size_t suggested_size, size_t suggested_size,
@ -93,7 +93,7 @@ static void ipc_alloc_cb(uv_handle_t* handle,
static void sv_async_cb(uv_async_t* handle, int status); static void sv_async_cb(uv_async_t* handle, int status);
static void sv_connection_cb(uv_stream_t* server_handle, int status); static void sv_connection_cb(uv_stream_t* server_handle, int status);
static void sv_read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf); static void sv_read_cb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf);
static void sv_alloc_cb(uv_handle_t* handle, static void sv_alloc_cb(uv_handle_t* handle,
size_t suggested_size, size_t suggested_size,
uv_buf_t* buf); uv_buf_t* buf);
@ -173,7 +173,7 @@ static void ipc_alloc_cb(uv_handle_t* handle,
static void ipc_read2_cb(uv_pipe_t* ipc_pipe, static void ipc_read2_cb(uv_pipe_t* ipc_pipe,
ssize_t nread, ssize_t nread,
uv_buf_t buf, const uv_buf_t* buf,
uv_handle_type type) { uv_handle_type type) {
struct ipc_client_ctx* ctx; struct ipc_client_ctx* ctx;
uv_loop_t* loop; uv_loop_t* loop;
@ -311,7 +311,9 @@ static void sv_alloc_cb(uv_handle_t* handle,
} }
static void sv_read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) { static void sv_read_cb(uv_stream_t* handle,
ssize_t nread,
const uv_buf_t* buf) {
ASSERT(nread == UV_EOF); ASSERT(nread == UV_EOF);
uv_close((uv_handle_t*) handle, (uv_close_cb) free); uv_close((uv_handle_t*) handle, (uv_close_cb) free);
} }

View File

@ -69,9 +69,8 @@ static void buf_alloc(uv_handle_t* tcp, size_t size, uv_buf_t* buf) {
} }
static void buf_free(uv_buf_t uv_buf_t) { static void buf_free(const uv_buf_t* buf) {
buf_t* ab = (buf_t*) (uv_buf_t.base - sizeof *ab); buf_t* ab = (buf_t*) buf->base - 1;
ab->next = buf_freelist; ab->next = buf_freelist;
buf_freelist = ab; buf_freelist = ab;
} }
@ -121,7 +120,9 @@ static void pinger_shutdown_cb(uv_shutdown_t* req, int status) {
} }
static void pinger_read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) { static void pinger_read_cb(uv_stream_t* tcp,
ssize_t nread,
const uv_buf_t* buf) {
ssize_t i; ssize_t i;
pinger_t* pinger; pinger_t* pinger;
@ -130,7 +131,7 @@ static void pinger_read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) {
if (nread < 0) { if (nread < 0) {
ASSERT(nread == UV_EOF); ASSERT(nread == UV_EOF);
if (buf.base) { if (buf->base) {
buf_free(buf); buf_free(buf);
} }
@ -142,7 +143,7 @@ static void pinger_read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) {
/* Now we count the pings */ /* Now we count the pings */
for (i = 0; i < nread; i++) { for (i = 0; i < nread; i++) {
ASSERT(buf.base[i] == PING[pinger->state]); ASSERT(buf->base[i] == PING[pinger->state]);
pinger->state = (pinger->state + 1) % (sizeof(PING) - 1); pinger->state = (pinger->state + 1) % (sizeof(PING) - 1);
if (pinger->state == 0) { if (pinger->state == 0) {
pinger->pongs++; pinger->pongs++;

View File

@ -77,7 +77,7 @@ static int conns_failed;
static void alloc_cb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf); static void alloc_cb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf);
static void connect_cb(uv_connect_t* conn_req, int status); static void connect_cb(uv_connect_t* conn_req, int status);
static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf); static void read_cb(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf);
static void close_cb(uv_handle_t* handle); static void close_cb(uv_handle_t* handle);
@ -135,7 +135,7 @@ static void connect_cb(uv_connect_t* req, int status) {
} }
static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) { static void read_cb(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) {
ASSERT(stream != NULL); ASSERT(stream != NULL);

View File

@ -42,7 +42,7 @@ static uv_req_t* req_alloc();
static void req_free(uv_req_t* uv_req); static void req_free(uv_req_t* uv_req);
static void buf_alloc(uv_handle_t* handle, size_t size, uv_buf_t* buf); static void buf_alloc(uv_handle_t* handle, size_t size, uv_buf_t* buf);
static void buf_free(uv_buf_t uv_buf_t); static void buf_free(const uv_buf_t* buf);
static uv_loop_t* loop; static uv_loop_t* loop;
@ -158,7 +158,7 @@ static void start_stats_collection(void) {
} }
static void read_cb(uv_stream_t* stream, ssize_t bytes, uv_buf_t buf) { static void read_cb(uv_stream_t* stream, ssize_t bytes, const uv_buf_t* buf) {
if (nrecv_total == 0) { if (nrecv_total == 0) {
ASSERT(start_time == 0); ASSERT(start_time == 0);
uv_update_time(loop); uv_update_time(loop);
@ -347,11 +347,10 @@ static void buf_alloc(uv_handle_t* handle, size_t size, uv_buf_t* buf) {
} }
static void buf_free(uv_buf_t uv_buf_t) { static void buf_free(const uv_buf_t* buf) {
buf_list_t* buf = (buf_list_t*) (uv_buf_t.base - sizeof *buf); buf_list_t* ab = (buf_list_t*) buf->base - 1;
ab->next = buf_freelist;
buf->next = buf_freelist; buf_freelist = ab;
buf_freelist = buf;
} }

View File

@ -88,7 +88,7 @@ static void pipe_close_cb(uv_handle_t* pipe) {
} }
static void on_read(uv_stream_t* pipe, ssize_t nread, uv_buf_t buf) { static void on_read(uv_stream_t* pipe, ssize_t nread, const uv_buf_t* buf) {
if (nread > 0) { if (nread > 0) {
ASSERT(pipe_open == 1); ASSERT(pipe_open == 1);
output_used += nread; output_used += nread;

View File

@ -34,7 +34,7 @@ static uv_tcp_t tcp_server;
static void connection_cb(uv_stream_t* stream, int status); static void connection_cb(uv_stream_t* stream, int status);
static void alloc_cb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf); static void alloc_cb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf);
static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf); static void read_cb(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf);
static void shutdown_cb(uv_shutdown_t* req, int status); static void shutdown_cb(uv_shutdown_t* req, int status);
static void close_cb(uv_handle_t* handle); static void close_cb(uv_handle_t* handle);
@ -69,7 +69,7 @@ static void alloc_cb(uv_handle_t* handle,
} }
static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) { static void read_cb(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) {
conn_rec* conn; conn_rec* conn;
int r; int r;

View File

@ -54,7 +54,7 @@ static uv_tcp_t server;
static void after_write(uv_write_t* req, int status); static void after_write(uv_write_t* req, int status);
static void after_read(uv_stream_t*, ssize_t nread, uv_buf_t buf); static void after_read(uv_stream_t*, ssize_t nread, const uv_buf_t* buf);
static void on_close(uv_handle_t* peer); static void on_close(uv_handle_t* peer);
static void on_connection(uv_stream_t*, int status); static void on_connection(uv_stream_t*, int status);
@ -124,7 +124,9 @@ static void addrsp(write_req_t* wr, char* hdr) {
wr->buf.len += rsplen; wr->buf.len += rsplen;
} }
static void process_req(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) { static void process_req(uv_stream_t* handle,
ssize_t nread,
const uv_buf_t* buf) {
write_req_t* wr; write_req_t* wr;
dnshandle* dns = (dnshandle*)handle; dnshandle* dns = (dnshandle*)handle;
char hdrbuf[DNSREC_LEN]; char hdrbuf[DNSREC_LEN];
@ -144,7 +146,7 @@ static void process_req(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) {
readbuf_remaining = dns->state.prevbuf_rem; readbuf_remaining = dns->state.prevbuf_rem;
usingprev = 1; usingprev = 1;
} else { } else {
dnsreq = buf.base; dnsreq = buf->base;
readbuf_remaining = nread; readbuf_remaining = nread;
} }
hdrstart = dnsreq; hdrstart = dnsreq;
@ -194,7 +196,7 @@ static void process_req(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) {
if (usingprev == 1) { if (usingprev == 1) {
/* free previous buffer */ /* free previous buffer */
free(dns->state.prevbuf_ptr); free(dns->state.prevbuf_ptr);
dnsreq = buf.base; dnsreq = buf->base;
readbuf_remaining = nread; readbuf_remaining = nread;
usingprev = 0; usingprev = 0;
} else { } else {
@ -211,27 +213,29 @@ static void process_req(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) {
if (readbuf_remaining > 0) { if (readbuf_remaining > 0) {
/* save start of record position, so we can continue on next read */ /* save start of record position, so we can continue on next read */
dns->state.prevbuf_ptr = buf.base; dns->state.prevbuf_ptr = buf->base;
dns->state.prevbuf_pos = hdrstart - buf.base; dns->state.prevbuf_pos = hdrstart - buf->base;
dns->state.prevbuf_rem = nread - dns->state.prevbuf_pos; dns->state.prevbuf_rem = nread - dns->state.prevbuf_pos;
} else { } else {
/* nothing left in this buffer */ /* nothing left in this buffer */
dns->state.prevbuf_ptr = NULL; dns->state.prevbuf_ptr = NULL;
dns->state.prevbuf_pos = 0; dns->state.prevbuf_pos = 0;
dns->state.prevbuf_rem = 0; dns->state.prevbuf_rem = 0;
free(buf.base); free(buf->base);
} }
} }
static void after_read(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) { static void after_read(uv_stream_t* handle,
ssize_t nread,
const uv_buf_t* buf) {
uv_shutdown_t* req; uv_shutdown_t* req;
if (nread < 0) { if (nread < 0) {
/* Error or EOF */ /* Error or EOF */
ASSERT(nread == UV_EOF); ASSERT(nread == UV_EOF);
if (buf.base) { if (buf->base) {
free(buf.base); free(buf->base);
} }
req = malloc(sizeof *req); req = malloc(sizeof *req);
@ -242,7 +246,7 @@ static void after_read(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) {
if (nread == 0) { if (nread == 0) {
/* Everything OK, but nothing read. */ /* Everything OK, but nothing read. */
free(buf.base); free(buf->base);
return; return;
} }
/* process requests and send responses */ /* process requests and send responses */

View File

@ -39,7 +39,7 @@ static uv_pipe_t pipeServer;
static uv_handle_t* server; static uv_handle_t* server;
static void after_write(uv_write_t* req, int status); static void after_write(uv_write_t* req, int status);
static void after_read(uv_stream_t*, ssize_t nread, uv_buf_t buf); static void after_read(uv_stream_t*, ssize_t nread, const uv_buf_t* buf);
static void on_close(uv_handle_t* peer); static void on_close(uv_handle_t* peer);
static void on_server_close(uv_handle_t* handle); static void on_server_close(uv_handle_t* handle);
static void on_connection(uv_stream_t*, int status); static void on_connection(uv_stream_t*, int status);
@ -72,7 +72,9 @@ static void after_shutdown(uv_shutdown_t* req, int status) {
} }
static void after_read(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) { static void after_read(uv_stream_t* handle,
ssize_t nread,
const uv_buf_t* buf) {
int i; int i;
write_req_t *wr; write_req_t *wr;
uv_shutdown_t* req; uv_shutdown_t* req;
@ -81,8 +83,8 @@ static void after_read(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) {
/* Error or EOF */ /* Error or EOF */
ASSERT(nread == UV_EOF); ASSERT(nread == UV_EOF);
if (buf.base) { if (buf->base) {
free(buf.base); free(buf->base);
} }
req = (uv_shutdown_t*) malloc(sizeof *req); req = (uv_shutdown_t*) malloc(sizeof *req);
@ -93,7 +95,7 @@ static void after_read(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) {
if (nread == 0) { if (nread == 0) {
/* Everything OK, but nothing read. */ /* Everything OK, but nothing read. */
free(buf.base); free(buf->base);
return; return;
} }
@ -103,9 +105,9 @@ static void after_read(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) {
*/ */
if (!server_closed) { if (!server_closed) {
for (i = 0; i < nread; i++) { for (i = 0; i < nread; i++) {
if (buf.base[i] == 'Q') { if (buf->base[i] == 'Q') {
if (i + 1 < nread && buf.base[i + 1] == 'S') { if (i + 1 < nread && buf->base[i + 1] == 'S') {
free(buf.base); free(buf->base);
uv_close((uv_handle_t*)handle, on_close); uv_close((uv_handle_t*)handle, on_close);
return; return;
} else { } else {
@ -118,7 +120,7 @@ static void after_read(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) {
wr = (write_req_t*) malloc(sizeof *wr); wr = (write_req_t*) malloc(sizeof *wr);
wr->buf = uv_buf_init(buf.base, nread); wr->buf = uv_buf_init(buf->base, nread);
if (uv_write(&wr->req, handle, &wr->buf, 1, after_write)) { if (uv_write(&wr->req, handle, &wr->buf, 1, after_write)) {
FATAL("uv_write failed"); FATAL("uv_write failed");
} }

View File

@ -67,11 +67,11 @@ static void shutdown_cb(uv_shutdown_t* req, int status) {
} }
static void read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) { static void read_cb(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* buf) {
ASSERT(nested == 0 && "read_cb must be called from a fresh stack"); ASSERT(nested == 0 && "read_cb must be called from a fresh stack");
printf("Read. nread == %d\n", (int)nread); printf("Read. nread == %d\n", (int)nread);
free(buf.base); free(buf->base);
if (nread == 0) { if (nread == 0) {
return; return;

View File

@ -115,11 +115,11 @@ static void start_server(void) {
} }
static void read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) { static void read_cb(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* buf) {
/* The server will not send anything, it should close gracefully. */ /* The server will not send anything, it should close gracefully. */
if (buf.base) { if (buf->base) {
free(buf.base); free(buf->base);
} }
if (nread >= 0) { if (nread >= 0) {

View File

@ -60,12 +60,14 @@ static void after_shutdown(uv_shutdown_t* req, int status) {
} }
static void after_read(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) { static void after_read(uv_stream_t* handle,
ssize_t nread,
const uv_buf_t* buf) {
uv_shutdown_t* req; uv_shutdown_t* req;
int r; int r;
if (buf.base) { if (buf->base) {
free(buf.base); free(buf->base);
} }
req = (uv_shutdown_t*) malloc(sizeof *req); req = (uv_shutdown_t*) malloc(sizeof *req);

View File

@ -62,7 +62,7 @@ static void alloc_cb(uv_handle_t* handle,
static void recv_cb(uv_pipe_t* handle, static void recv_cb(uv_pipe_t* handle,
ssize_t nread, ssize_t nread,
uv_buf_t buf, const uv_buf_t* buf,
uv_handle_type pending) { uv_handle_type pending) {
int r; int r;
@ -164,15 +164,16 @@ static void write2_cb(uv_write_t* req, int status) {
static void read2_cb(uv_pipe_t* handle, static void read2_cb(uv_pipe_t* handle,
ssize_t nread, ssize_t nread,
uv_buf_t buf, const uv_buf_t* rdbuf,
uv_handle_type pending) { uv_handle_type pending) {
uv_buf_t wrbuf;
int r; int r;
ASSERT(pending == UV_NAMED_PIPE || pending == UV_TCP); ASSERT(pending == UV_NAMED_PIPE || pending == UV_TCP);
ASSERT(handle == &ctx.channel); ASSERT(handle == &ctx.channel);
ASSERT(nread >= 0); ASSERT(nread >= 0);
buf = uv_buf_init(".", 1); wrbuf = uv_buf_init(".", 1);
if (pending == UV_NAMED_PIPE) if (pending == UV_NAMED_PIPE)
r = uv_pipe_init(ctx.channel.loop, &ctx.recv.pipe, 0); r = uv_pipe_init(ctx.channel.loop, &ctx.recv.pipe, 0);
@ -187,7 +188,8 @@ static void read2_cb(uv_pipe_t* handle,
r = uv_write2(&ctx.write_req, r = uv_write2(&ctx.write_req,
(uv_stream_t*)&ctx.channel, (uv_stream_t*)&ctx.channel,
&buf, 1, &wrbuf,
1,
&ctx.recv.stream, &ctx.recv.stream,
write2_cb); write2_cb);
ASSERT(r == 0); ASSERT(r == 0);

View File

@ -135,20 +135,22 @@ static void make_many_connections(void) {
} }
static void on_read(uv_pipe_t* pipe, ssize_t nread, uv_buf_t buf, static void on_read(uv_pipe_t* pipe,
uv_handle_type pending) { ssize_t nread,
const uv_buf_t* buf,
uv_handle_type pending) {
int r; int r;
uv_buf_t outbuf; uv_buf_t outbuf;
if (nread == 0) { if (nread == 0) {
/* Everything OK, but nothing read. */ /* Everything OK, but nothing read. */
free(buf.base); free(buf->base);
return; return;
} }
if (nread < 0) { if (nread < 0) {
if (nread == UV_EOF) { if (nread == UV_EOF) {
free(buf.base); free(buf->base);
return; return;
} }
@ -159,7 +161,7 @@ static void on_read(uv_pipe_t* pipe, ssize_t nread, uv_buf_t buf,
fprintf(stderr, "got %d bytes\n", (int)nread); fprintf(stderr, "got %d bytes\n", (int)nread);
if (!tcp_server_listening) { if (!tcp_server_listening) {
ASSERT(nread > 0 && buf.base && pending != UV_UNKNOWN_HANDLE); ASSERT(nread > 0 && buf->base && pending != UV_UNKNOWN_HANDLE);
read2_cb_called++; read2_cb_called++;
/* Accept the pending TCP server, and start listening on it. */ /* Accept the pending TCP server, and start listening on it. */
@ -176,7 +178,7 @@ static void on_read(uv_pipe_t* pipe, ssize_t nread, uv_buf_t buf,
tcp_server_listening = 1; tcp_server_listening = 1;
/* Make sure that the expected data is correctly multiplexed. */ /* Make sure that the expected data is correctly multiplexed. */
ASSERT(memcmp("hello\n", buf.base, nread) == 0); ASSERT(memcmp("hello\n", buf->base, nread) == 0);
outbuf = uv_buf_init("world\n", 6); outbuf = uv_buf_init("world\n", 6);
r = uv_write(&write_req, (uv_stream_t*)pipe, &outbuf, 1, NULL); r = uv_write(&write_req, (uv_stream_t*)pipe, &outbuf, 1, NULL);
@ -184,14 +186,14 @@ static void on_read(uv_pipe_t* pipe, ssize_t nread, uv_buf_t buf,
/* Create a bunch of connections to get both servers to accept. */ /* Create a bunch of connections to get both servers to accept. */
make_many_connections(); make_many_connections();
} else if (memcmp("accepted_connection\n", buf.base, nread) == 0) { } else if (memcmp("accepted_connection\n", buf->base, nread) == 0) {
/* Remote server has accepted a connection. Close the channel. */ /* Remote server has accepted a connection. Close the channel. */
ASSERT(pending == UV_UNKNOWN_HANDLE); ASSERT(pending == UV_UNKNOWN_HANDLE);
remote_conn_accepted = 1; remote_conn_accepted = 1;
uv_close((uv_handle_t*)&channel, NULL); uv_close((uv_handle_t*)&channel, NULL);
} }
free(buf.base); free(buf->base);
} }
@ -249,11 +251,11 @@ static void on_read_alloc(uv_handle_t* handle,
} }
static void on_tcp_read(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) { static void on_tcp_read(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* buf) {
ASSERT(nread > 0); ASSERT(nread > 0);
ASSERT(memcmp("hello again\n", buf.base, nread) == 0); ASSERT(memcmp("hello again\n", buf->base, nread) == 0);
ASSERT(tcp == (uv_stream_t*)&tcp_connection); ASSERT(tcp == (uv_stream_t*)&tcp_connection);
free(buf.base); free(buf->base);
tcp_read_cb_called++; tcp_read_cb_called++;
@ -262,20 +264,22 @@ static void on_tcp_read(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) {
} }
static void on_read_connection(uv_pipe_t* pipe, ssize_t nread, uv_buf_t buf, static void on_read_connection(uv_pipe_t* pipe,
uv_handle_type pending) { ssize_t nread,
const uv_buf_t* buf,
uv_handle_type pending) {
int r; int r;
uv_buf_t outbuf; uv_buf_t outbuf;
if (nread == 0) { if (nread == 0) {
/* Everything OK, but nothing read. */ /* Everything OK, but nothing read. */
free(buf.base); free(buf->base);
return; return;
} }
if (nread < 0) { if (nread < 0) {
if (nread == UV_EOF) { if (nread == UV_EOF) {
free(buf.base); free(buf->base);
return; return;
} }
@ -285,7 +289,7 @@ static void on_read_connection(uv_pipe_t* pipe, ssize_t nread, uv_buf_t buf,
fprintf(stderr, "got %d bytes\n", (int)nread); fprintf(stderr, "got %d bytes\n", (int)nread);
ASSERT(nread > 0 && buf.base && pending != UV_UNKNOWN_HANDLE); ASSERT(nread > 0 && buf->base && pending != UV_UNKNOWN_HANDLE);
read2_cb_called++; read2_cb_called++;
/* Accept the pending TCP connection */ /* Accept the pending TCP connection */
@ -297,7 +301,7 @@ static void on_read_connection(uv_pipe_t* pipe, ssize_t nread, uv_buf_t buf,
ASSERT(r == 0); ASSERT(r == 0);
/* Make sure that the expected data is correctly multiplexed. */ /* Make sure that the expected data is correctly multiplexed. */
ASSERT(memcmp("hello\n", buf.base, nread) == 0); ASSERT(memcmp("hello\n", buf->base, nread) == 0);
/* Write/read to/from the connection */ /* Write/read to/from the connection */
outbuf = uv_buf_init("world\n", 6); outbuf = uv_buf_init("world\n", 6);
@ -308,7 +312,7 @@ static void on_read_connection(uv_pipe_t* pipe, ssize_t nread, uv_buf_t buf,
r = uv_read_start((uv_stream_t*)&tcp_connection, on_read_alloc, on_tcp_read); r = uv_read_start((uv_stream_t*)&tcp_connection, on_read_alloc, on_tcp_read);
ASSERT(r == 0); ASSERT(r == 0);
free(buf.base); free(buf->base);
} }
@ -430,13 +434,15 @@ static void tcp_connection_write_cb(uv_write_t* req, int status) {
} }
static void on_tcp_child_process_read(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) { static void on_tcp_child_process_read(uv_stream_t* tcp,
ssize_t nread,
const uv_buf_t* buf) {
uv_buf_t outbuf; uv_buf_t outbuf;
int r; int r;
if (nread < 0) { if (nread < 0) {
if (nread == UV_EOF) { if (nread == UV_EOF) {
free(buf.base); free(buf->base);
return; return;
} }
@ -445,9 +451,9 @@ static void on_tcp_child_process_read(uv_stream_t* tcp, ssize_t nread, uv_buf_t
} }
ASSERT(nread > 0); ASSERT(nread > 0);
ASSERT(memcmp("world\n", buf.base, nread) == 0); ASSERT(memcmp("world\n", buf->base, nread) == 0);
on_pipe_read_called++; on_pipe_read_called++;
free(buf.base); free(buf->base);
/* Write to the socket */ /* Write to the socket */
outbuf = uv_buf_init("hello again\n", 12); outbuf = uv_buf_init("hello again\n", 12);
@ -520,7 +526,9 @@ static void ipc_on_connection_tcp_conn(uv_stream_t* server, int status) {
(uv_stream_t*)conn, NULL); (uv_stream_t*)conn, NULL);
ASSERT(r == 0); ASSERT(r == 0);
r = uv_read_start((uv_stream_t*)conn, on_read_alloc, on_tcp_child_process_read); r = uv_read_start((uv_stream_t*) conn,
on_read_alloc,
on_tcp_child_process_read);
ASSERT(r == 0); ASSERT(r == 0);
uv_close((uv_handle_t*)conn, close_cb); uv_close((uv_handle_t*)conn, close_cb);

View File

@ -37,7 +37,7 @@ static void alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf) {
} }
static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) { static void read_cb(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) {
fprintf(stdout, "got data %d\n", ++read_count); fprintf(stdout, "got data %d\n", ++read_count);
if (read_count == 3) if (read_count == 3)

View File

@ -86,7 +86,9 @@ static void pinger_write_ping(pinger_t* pinger) {
} }
static void pinger_read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) { static void pinger_read_cb(uv_stream_t* stream,
ssize_t nread,
const uv_buf_t* buf) {
ssize_t i; ssize_t i;
pinger_t* pinger; pinger_t* pinger;
@ -96,7 +98,7 @@ static void pinger_read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) {
ASSERT(nread == UV_EOF); ASSERT(nread == UV_EOF);
puts("got EOF"); puts("got EOF");
free(buf.base); free(buf->base);
uv_close((uv_handle_t*)(&pinger->stream.tcp), pinger_on_close); uv_close((uv_handle_t*)(&pinger->stream.tcp), pinger_on_close);
@ -105,7 +107,7 @@ static void pinger_read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) {
/* Now we count the pings */ /* Now we count the pings */
for (i = 0; i < nread; i++) { for (i = 0; i < nread; i++) {
ASSERT(buf.base[i] == PING[pinger->state]); ASSERT(buf->base[i] == PING[pinger->state]);
pinger->state = (pinger->state + 1) % (sizeof(PING) - 1); pinger->state = (pinger->state + 1) % (sizeof(PING) - 1);
if (pinger->state != 0) if (pinger->state != 0)
@ -122,7 +124,7 @@ static void pinger_read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) {
} }
} }
free(buf.base); free(buf->base);
} }

View File

@ -45,25 +45,25 @@ static void alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf) {
} }
static void read_cb(uv_stream_t* t, ssize_t nread, uv_buf_t buf) { static void read_cb(uv_stream_t* t, ssize_t nread, const uv_buf_t* buf) {
ASSERT((uv_tcp_t*)t == &tcp); ASSERT((uv_tcp_t*)t == &tcp);
if (nread == 0) { if (nread == 0) {
free(buf.base); free(buf->base);
return; return;
} }
if (!got_q) { if (!got_q) {
ASSERT(nread == 1); ASSERT(nread == 1);
ASSERT(!got_eof); ASSERT(!got_eof);
ASSERT(buf.base[0] == 'Q'); ASSERT(buf->base[0] == 'Q');
free(buf.base); free(buf->base);
got_q = 1; got_q = 1;
puts("got Q"); puts("got Q");
} else { } else {
ASSERT(nread == UV_EOF); ASSERT(nread == UV_EOF);
if (buf.base) { if (buf->base) {
free(buf.base); free(buf->base);
} }
got_eof = 1; got_eof = 1;
puts("got EOF"); puts("got EOF");

View File

@ -126,7 +126,7 @@ static void on_alloc(uv_handle_t* handle,
} }
static void on_read(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) { static void on_read(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* buf) {
if (nread > 0) { if (nread > 0) {
output_used += nread; output_used += nread;
} else if (nread < 0) { } else if (nread < 0) {

View File

@ -95,7 +95,7 @@ static void after_write(uv_write_t* req, int status) {
} }
static void on_read(uv_stream_t* tcp, ssize_t nread, uv_buf_t rdbuf) { static void on_read(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* rdbuf) {
uv_write_t* req; uv_write_t* req;
uv_buf_t wrbuf; uv_buf_t wrbuf;
int r; int r;
@ -164,12 +164,12 @@ static int after_write_called;
static uv_pipe_t stdin_pipe; static uv_pipe_t stdin_pipe;
static uv_pipe_t stdout_pipe; static uv_pipe_t stdout_pipe;
static void on_pipe_read(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) { static void on_pipe_read(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* buf) {
ASSERT(nread > 0); ASSERT(nread > 0);
ASSERT(memcmp("hello world\n", buf.base, nread) == 0); ASSERT(memcmp("hello world\n", buf->base, nread) == 0);
on_pipe_read_called++; on_pipe_read_called++;
free(buf.base); free(buf->base);
uv_close((uv_handle_t*)&stdin_pipe, close_cb); uv_close((uv_handle_t*)&stdin_pipe, close_cb);
uv_close((uv_handle_t*)&stdout_pipe, close_cb); uv_close((uv_handle_t*)&stdout_pipe, close_cb);
@ -242,8 +242,7 @@ int stdio_over_pipes_helper(void) {
uv_ref((uv_handle_t*)&stdout_pipe); uv_ref((uv_handle_t*)&stdout_pipe);
uv_ref((uv_handle_t*)&stdin_pipe); uv_ref((uv_handle_t*)&stdin_pipe);
r = uv_read_start((uv_stream_t*)&stdin_pipe, on_read_alloc, r = uv_read_start((uv_stream_t*)&stdin_pipe, on_read_alloc, on_pipe_read);
on_pipe_read);
ASSERT(r == 0); ASSERT(r == 0);
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);

View File

@ -96,12 +96,12 @@ static void shutdown_cb(uv_shutdown_t* req, int status) {
} }
static void read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) { static void read_cb(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* buf) {
ASSERT(tcp != NULL); ASSERT(tcp != NULL);
if (nread >= 0) { if (nread >= 0) {
ASSERT(nread == 4); ASSERT(nread == 4);
ASSERT(memcmp("PING", buf.base, nread) == 0); ASSERT(memcmp("PING", buf->base, nread) == 0);
} }
else { else {
ASSERT(nread == UV_EOF); ASSERT(nread == UV_EOF);

View File

@ -73,7 +73,7 @@ static void timer_cb(uv_timer_t* handle, int status) {
} }
static void read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) { static void read_cb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) {
} }

View File

@ -54,7 +54,7 @@ static void alloc_cb(uv_handle_t* handle,
} }
static void read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) { static void read_cb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) {
ASSERT(0 && "read_cb should not have been called"); ASSERT(0 && "read_cb should not have been called");
} }

View File

@ -29,7 +29,7 @@
static void connection_cb(uv_stream_t* server, int status); static void connection_cb(uv_stream_t* server, int status);
static void connect_cb(uv_connect_t* req, int status); static void connect_cb(uv_connect_t* req, int status);
static void write_cb(uv_write_t* req, int status); static void write_cb(uv_write_t* req, int status);
static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf); static void read_cb(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf);
static void alloc_cb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf); static void alloc_cb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf);
static uv_tcp_t tcp_server; static uv_tcp_t tcp_server;
@ -74,7 +74,7 @@ static void alloc_cb(uv_handle_t* handle,
} }
static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) { static void read_cb(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) {
if (nread < 0) { if (nread < 0) {
fprintf(stderr, "read_cb error: %s\n", uv_err_name(nread)); fprintf(stderr, "read_cb error: %s\n", uv_err_name(nread));
ASSERT(nread == UV_ECONNRESET || nread == UV_EOF); ASSERT(nread == UV_ECONNRESET || nread == UV_EOF);

View File

@ -77,7 +77,7 @@ static void shutdown_cb(uv_shutdown_t* req, int status) {
} }
static void read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) { static void read_cb(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* buf) {
ASSERT(tcp != NULL); ASSERT(tcp != NULL);
if (nread >= 0) { if (nread >= 0) {
@ -89,7 +89,7 @@ static void read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) {
uv_close((uv_handle_t*)tcp, close_cb); uv_close((uv_handle_t*)tcp, close_cb);
} }
free(buf.base); free(buf->base);
} }