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:
parent
3fb6612233
commit
b7d027c3a8
14
include/uv.h
14
include/uv.h
@ -361,18 +361,22 @@ typedef void (*uv_alloc_cb)(uv_handle_t* handle,
|
||||
* Trying to read from the stream again is undefined.
|
||||
*
|
||||
* 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
|
||||
* or error.
|
||||
* The buffer may be a null buffer (where buf->base=NULL and buf->len=0) on
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
typedef void (*uv_read2_cb)(uv_pipe_t* pipe, ssize_t nread, uv_buf_t buf,
|
||||
uv_handle_type pending);
|
||||
typedef void (*uv_read2_cb)(uv_pipe_t* pipe,
|
||||
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_connect_cb)(uv_connect_t* req, int status);
|
||||
|
||||
@ -938,7 +938,7 @@ static uv_handle_type uv__handle_type(int fd) {
|
||||
|
||||
static void uv__stream_read_cb(uv_stream_t* stream,
|
||||
int status,
|
||||
uv_buf_t buf,
|
||||
const uv_buf_t* buf,
|
||||
uv_handle_type type) {
|
||||
if (stream->read_cb != NULL)
|
||||
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;
|
||||
uv__io_stop(stream->loop, &stream->io_watcher, UV__POLLIN);
|
||||
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);
|
||||
if (buf.len == 0) {
|
||||
/* 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;
|
||||
}
|
||||
|
||||
@ -1019,23 +1019,23 @@ static void uv__read(uv_stream_t* stream) {
|
||||
if (stream->flags & UV_STREAM_READING) {
|
||||
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 {
|
||||
/* 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) &&
|
||||
"stream->read_cb(status=-1) did not call uv_close()");
|
||||
}
|
||||
return;
|
||||
} else if (nread == 0) {
|
||||
uv__stream_eof(stream, buf);
|
||||
uv__stream_eof(stream, &buf);
|
||||
return;
|
||||
} else {
|
||||
/* Successful read */
|
||||
ssize_t buflen = buf.len;
|
||||
|
||||
if (stream->read_cb) {
|
||||
stream->read_cb(stream, nread, buf);
|
||||
stream->read_cb(stream, nread, &buf);
|
||||
} else {
|
||||
assert(stream->read2_cb);
|
||||
|
||||
@ -1070,10 +1070,12 @@ static void uv__read(uv_stream_t* stream) {
|
||||
|
||||
|
||||
if (stream->accepted_fd >= 0) {
|
||||
stream->read2_cb((uv_pipe_t*)stream, nread, buf,
|
||||
uv__handle_type(stream->accepted_fd));
|
||||
stream->read2_cb((uv_pipe_t*) stream,
|
||||
nread,
|
||||
&buf,
|
||||
uv__handle_type(stream->accepted_fd));
|
||||
} 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_EOF)) {
|
||||
uv_buf_t buf = { NULL, 0 };
|
||||
uv__stream_eof(stream, buf);
|
||||
uv__stream_eof(stream, &buf);
|
||||
}
|
||||
|
||||
if (uv__stream_fd(stream) == -1)
|
||||
|
||||
@ -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);
|
||||
|
||||
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 {
|
||||
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) {
|
||||
handle->read2_cb(handle,
|
||||
uv_translate_sys_error(error),
|
||||
buf,
|
||||
&buf,
|
||||
UV_UNKNOWN_HANDLE);
|
||||
} 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);
|
||||
if (buf.len == 0) {
|
||||
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) {
|
||||
handle->read_cb((uv_stream_t*) handle, UV_ENOBUFS, buf);
|
||||
handle->read_cb((uv_stream_t*) handle, UV_ENOBUFS, &buf);
|
||||
}
|
||||
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 - bytes;
|
||||
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);
|
||||
} 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) {
|
||||
@ -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;
|
||||
}
|
||||
} 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 */
|
||||
|
||||
@ -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->alloc_cb((uv_handle_t*) handle, 65536, &handle->read_buffer);
|
||||
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;
|
||||
}
|
||||
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,
|
||||
uv_translate_sys_error(err),
|
||||
buf);
|
||||
&buf);
|
||||
}
|
||||
} else {
|
||||
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 */
|
||||
handle->read_cb((uv_stream_t*)handle,
|
||||
req->overlapped.InternalHigh,
|
||||
handle->read_buffer);
|
||||
&handle->read_buffer);
|
||||
/* Read again only if bytes == buf.len */
|
||||
if (req->overlapped.InternalHigh < handle->read_buffer.len) {
|
||||
goto done;
|
||||
@ -940,7 +940,7 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
|
||||
|
||||
buf.base = 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;
|
||||
}
|
||||
}
|
||||
@ -949,7 +949,7 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
|
||||
while (handle->flags & UV_HANDLE_READING) {
|
||||
handle->alloc_cb((uv_handle_t*) handle, 65536, &buf);
|
||||
if (buf.len == 0) {
|
||||
handle->read_cb(handle, UV_ENOBUFS, buf);
|
||||
handle->read_cb((uv_stream_t*) handle, UV_ENOBUFS, &buf);
|
||||
break;
|
||||
}
|
||||
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) {
|
||||
if (bytes > 0) {
|
||||
/* 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 */
|
||||
if (bytes < buf.len) {
|
||||
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);
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
err = WSAGetLastError();
|
||||
if (err == WSAEWOULDBLOCK) {
|
||||
/* 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 {
|
||||
/* Ouch! serious error. */
|
||||
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,
|
||||
uv_translate_sys_error(err),
|
||||
buf);
|
||||
&buf);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
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;
|
||||
}
|
||||
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->read_cb((uv_stream_t*)handle,
|
||||
uv_translate_sys_error(GET_REQ_ERROR(req)),
|
||||
uv_null_buf_);
|
||||
&uv_null_buf_);
|
||||
}
|
||||
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);
|
||||
handle->read_cb((uv_stream_t*)handle,
|
||||
uv_translate_sys_error(GetLastError()),
|
||||
uv_null_buf_);
|
||||
&uv_null_buf_);
|
||||
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);
|
||||
handle->read_cb((uv_stream_t*) handle,
|
||||
uv_translate_sys_error(GetLastError()),
|
||||
buf);
|
||||
&buf);
|
||||
goto out;
|
||||
}
|
||||
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);
|
||||
handle->read_cb((uv_stream_t*) handle,
|
||||
uv_translate_sys_error(GetLastError()),
|
||||
buf);
|
||||
&buf);
|
||||
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) {
|
||||
handle->alloc_cb((uv_handle_t*) handle, 1024, &buf);
|
||||
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;
|
||||
}
|
||||
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 (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_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 */
|
||||
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:
|
||||
@ -755,17 +757,17 @@ void uv_process_tty_read_line_req(uv_loop_t* loop, uv_tty_t* handle,
|
||||
DECREASE_ACTIVE_COUNT(loop, handle);
|
||||
handle->read_cb((uv_stream_t*) handle,
|
||||
uv_translate_sys_error(GET_REQ_ERROR(req)),
|
||||
buf);
|
||||
&buf);
|
||||
} else {
|
||||
/* 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 {
|
||||
/* Read successful */
|
||||
/* TODO: read unicode, convert to utf-8 */
|
||||
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. */
|
||||
|
||||
@ -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_read2_cb(uv_pipe_t* ipc_pipe,
|
||||
ssize_t nread,
|
||||
uv_buf_t buf,
|
||||
const uv_buf_t* buf,
|
||||
uv_handle_type type);
|
||||
static void ipc_alloc_cb(uv_handle_t* handle,
|
||||
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_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,
|
||||
size_t suggested_size,
|
||||
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,
|
||||
ssize_t nread,
|
||||
uv_buf_t buf,
|
||||
const uv_buf_t* buf,
|
||||
uv_handle_type type) {
|
||||
struct ipc_client_ctx* ctx;
|
||||
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);
|
||||
uv_close((uv_handle_t*) handle, (uv_close_cb) free);
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
buf_t* ab = (buf_t*) (uv_buf_t.base - sizeof *ab);
|
||||
|
||||
static void buf_free(const uv_buf_t* buf) {
|
||||
buf_t* ab = (buf_t*) buf->base - 1;
|
||||
ab->next = buf_freelist;
|
||||
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;
|
||||
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) {
|
||||
ASSERT(nread == UV_EOF);
|
||||
|
||||
if (buf.base) {
|
||||
if (buf->base) {
|
||||
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 */
|
||||
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);
|
||||
if (pinger->state == 0) {
|
||||
pinger->pongs++;
|
||||
|
||||
@ -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 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);
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -42,7 +42,7 @@ static uv_req_t* req_alloc();
|
||||
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_free(uv_buf_t uv_buf_t);
|
||||
static void buf_free(const uv_buf_t* buf);
|
||||
|
||||
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) {
|
||||
ASSERT(start_time == 0);
|
||||
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) {
|
||||
buf_list_t* buf = (buf_list_t*) (uv_buf_t.base - sizeof *buf);
|
||||
|
||||
buf->next = buf_freelist;
|
||||
buf_freelist = buf;
|
||||
static void buf_free(const uv_buf_t* buf) {
|
||||
buf_list_t* ab = (buf_list_t*) buf->base - 1;
|
||||
ab->next = buf_freelist;
|
||||
buf_freelist = ab;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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) {
|
||||
ASSERT(pipe_open == 1);
|
||||
output_used += nread;
|
||||
|
||||
@ -34,7 +34,7 @@ static uv_tcp_t tcp_server;
|
||||
|
||||
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 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 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;
|
||||
int r;
|
||||
|
||||
|
||||
@ -54,7 +54,7 @@ static uv_tcp_t server;
|
||||
|
||||
|
||||
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_connection(uv_stream_t*, int status);
|
||||
|
||||
@ -124,7 +124,9 @@ static void addrsp(write_req_t* wr, char* hdr) {
|
||||
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;
|
||||
dnshandle* dns = (dnshandle*)handle;
|
||||
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;
|
||||
usingprev = 1;
|
||||
} else {
|
||||
dnsreq = buf.base;
|
||||
dnsreq = buf->base;
|
||||
readbuf_remaining = nread;
|
||||
}
|
||||
hdrstart = dnsreq;
|
||||
@ -194,7 +196,7 @@ static void process_req(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) {
|
||||
if (usingprev == 1) {
|
||||
/* free previous buffer */
|
||||
free(dns->state.prevbuf_ptr);
|
||||
dnsreq = buf.base;
|
||||
dnsreq = buf->base;
|
||||
readbuf_remaining = nread;
|
||||
usingprev = 0;
|
||||
} else {
|
||||
@ -211,27 +213,29 @@ static void process_req(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) {
|
||||
|
||||
if (readbuf_remaining > 0) {
|
||||
/* save start of record position, so we can continue on next read */
|
||||
dns->state.prevbuf_ptr = buf.base;
|
||||
dns->state.prevbuf_pos = hdrstart - buf.base;
|
||||
dns->state.prevbuf_ptr = buf->base;
|
||||
dns->state.prevbuf_pos = hdrstart - buf->base;
|
||||
dns->state.prevbuf_rem = nread - dns->state.prevbuf_pos;
|
||||
} else {
|
||||
/* nothing left in this buffer */
|
||||
dns->state.prevbuf_ptr = NULL;
|
||||
dns->state.prevbuf_pos = 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;
|
||||
|
||||
if (nread < 0) {
|
||||
/* Error or EOF */
|
||||
ASSERT(nread == UV_EOF);
|
||||
|
||||
if (buf.base) {
|
||||
free(buf.base);
|
||||
if (buf->base) {
|
||||
free(buf->base);
|
||||
}
|
||||
|
||||
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) {
|
||||
/* Everything OK, but nothing read. */
|
||||
free(buf.base);
|
||||
free(buf->base);
|
||||
return;
|
||||
}
|
||||
/* process requests and send responses */
|
||||
|
||||
@ -39,7 +39,7 @@ static uv_pipe_t pipeServer;
|
||||
static uv_handle_t* server;
|
||||
|
||||
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_server_close(uv_handle_t* handle);
|
||||
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;
|
||||
write_req_t *wr;
|
||||
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 */
|
||||
ASSERT(nread == UV_EOF);
|
||||
|
||||
if (buf.base) {
|
||||
free(buf.base);
|
||||
if (buf->base) {
|
||||
free(buf->base);
|
||||
}
|
||||
|
||||
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) {
|
||||
/* Everything OK, but nothing read. */
|
||||
free(buf.base);
|
||||
free(buf->base);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -103,9 +105,9 @@ static void after_read(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) {
|
||||
*/
|
||||
if (!server_closed) {
|
||||
for (i = 0; i < nread; i++) {
|
||||
if (buf.base[i] == 'Q') {
|
||||
if (i + 1 < nread && buf.base[i + 1] == 'S') {
|
||||
free(buf.base);
|
||||
if (buf->base[i] == 'Q') {
|
||||
if (i + 1 < nread && buf->base[i + 1] == 'S') {
|
||||
free(buf->base);
|
||||
uv_close((uv_handle_t*)handle, on_close);
|
||||
return;
|
||||
} 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->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)) {
|
||||
FATAL("uv_write failed");
|
||||
}
|
||||
|
||||
@ -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");
|
||||
|
||||
printf("Read. nread == %d\n", (int)nread);
|
||||
free(buf.base);
|
||||
free(buf->base);
|
||||
|
||||
if (nread == 0) {
|
||||
return;
|
||||
|
||||
@ -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. */
|
||||
|
||||
if (buf.base) {
|
||||
free(buf.base);
|
||||
if (buf->base) {
|
||||
free(buf->base);
|
||||
}
|
||||
|
||||
if (nread >= 0) {
|
||||
|
||||
@ -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;
|
||||
int r;
|
||||
|
||||
if (buf.base) {
|
||||
free(buf.base);
|
||||
if (buf->base) {
|
||||
free(buf->base);
|
||||
}
|
||||
|
||||
req = (uv_shutdown_t*) malloc(sizeof *req);
|
||||
|
||||
@ -62,7 +62,7 @@ static void alloc_cb(uv_handle_t* handle,
|
||||
|
||||
static void recv_cb(uv_pipe_t* handle,
|
||||
ssize_t nread,
|
||||
uv_buf_t buf,
|
||||
const uv_buf_t* buf,
|
||||
uv_handle_type pending) {
|
||||
int r;
|
||||
|
||||
@ -164,15 +164,16 @@ static void write2_cb(uv_write_t* req, int status) {
|
||||
|
||||
static void read2_cb(uv_pipe_t* handle,
|
||||
ssize_t nread,
|
||||
uv_buf_t buf,
|
||||
const uv_buf_t* rdbuf,
|
||||
uv_handle_type pending) {
|
||||
uv_buf_t wrbuf;
|
||||
int r;
|
||||
|
||||
ASSERT(pending == UV_NAMED_PIPE || pending == UV_TCP);
|
||||
ASSERT(handle == &ctx.channel);
|
||||
ASSERT(nread >= 0);
|
||||
|
||||
buf = uv_buf_init(".", 1);
|
||||
wrbuf = uv_buf_init(".", 1);
|
||||
|
||||
if (pending == UV_NAMED_PIPE)
|
||||
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,
|
||||
(uv_stream_t*)&ctx.channel,
|
||||
&buf, 1,
|
||||
&wrbuf,
|
||||
1,
|
||||
&ctx.recv.stream,
|
||||
write2_cb);
|
||||
ASSERT(r == 0);
|
||||
|
||||
@ -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,
|
||||
uv_handle_type pending) {
|
||||
static void on_read(uv_pipe_t* pipe,
|
||||
ssize_t nread,
|
||||
const uv_buf_t* buf,
|
||||
uv_handle_type pending) {
|
||||
int r;
|
||||
uv_buf_t outbuf;
|
||||
|
||||
if (nread == 0) {
|
||||
/* Everything OK, but nothing read. */
|
||||
free(buf.base);
|
||||
free(buf->base);
|
||||
return;
|
||||
}
|
||||
|
||||
if (nread < 0) {
|
||||
if (nread == UV_EOF) {
|
||||
free(buf.base);
|
||||
free(buf->base);
|
||||
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);
|
||||
|
||||
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++;
|
||||
|
||||
/* 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;
|
||||
|
||||
/* 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);
|
||||
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. */
|
||||
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. */
|
||||
ASSERT(pending == UV_UNKNOWN_HANDLE);
|
||||
remote_conn_accepted = 1;
|
||||
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(memcmp("hello again\n", buf.base, nread) == 0);
|
||||
ASSERT(memcmp("hello again\n", buf->base, nread) == 0);
|
||||
ASSERT(tcp == (uv_stream_t*)&tcp_connection);
|
||||
free(buf.base);
|
||||
free(buf->base);
|
||||
|
||||
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,
|
||||
uv_handle_type pending) {
|
||||
static void on_read_connection(uv_pipe_t* pipe,
|
||||
ssize_t nread,
|
||||
const uv_buf_t* buf,
|
||||
uv_handle_type pending) {
|
||||
int r;
|
||||
uv_buf_t outbuf;
|
||||
|
||||
if (nread == 0) {
|
||||
/* Everything OK, but nothing read. */
|
||||
free(buf.base);
|
||||
free(buf->base);
|
||||
return;
|
||||
}
|
||||
|
||||
if (nread < 0) {
|
||||
if (nread == UV_EOF) {
|
||||
free(buf.base);
|
||||
free(buf->base);
|
||||
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);
|
||||
|
||||
ASSERT(nread > 0 && buf.base && pending != UV_UNKNOWN_HANDLE);
|
||||
ASSERT(nread > 0 && buf->base && pending != UV_UNKNOWN_HANDLE);
|
||||
read2_cb_called++;
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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 */
|
||||
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);
|
||||
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;
|
||||
int r;
|
||||
|
||||
if (nread < 0) {
|
||||
if (nread == UV_EOF) {
|
||||
free(buf.base);
|
||||
free(buf->base);
|
||||
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(memcmp("world\n", buf.base, nread) == 0);
|
||||
ASSERT(memcmp("world\n", buf->base, nread) == 0);
|
||||
on_pipe_read_called++;
|
||||
free(buf.base);
|
||||
free(buf->base);
|
||||
|
||||
/* Write to the socket */
|
||||
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);
|
||||
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);
|
||||
|
||||
uv_close((uv_handle_t*)conn, close_cb);
|
||||
|
||||
@ -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);
|
||||
|
||||
if (read_count == 3)
|
||||
|
||||
@ -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;
|
||||
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);
|
||||
|
||||
puts("got EOF");
|
||||
free(buf.base);
|
||||
free(buf->base);
|
||||
|
||||
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 */
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
if (nread == 0) {
|
||||
free(buf.base);
|
||||
free(buf->base);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!got_q) {
|
||||
ASSERT(nread == 1);
|
||||
ASSERT(!got_eof);
|
||||
ASSERT(buf.base[0] == 'Q');
|
||||
free(buf.base);
|
||||
ASSERT(buf->base[0] == 'Q');
|
||||
free(buf->base);
|
||||
got_q = 1;
|
||||
puts("got Q");
|
||||
} else {
|
||||
ASSERT(nread == UV_EOF);
|
||||
if (buf.base) {
|
||||
free(buf.base);
|
||||
if (buf->base) {
|
||||
free(buf->base);
|
||||
}
|
||||
got_eof = 1;
|
||||
puts("got EOF");
|
||||
|
||||
@ -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) {
|
||||
output_used += nread;
|
||||
} else if (nread < 0) {
|
||||
|
||||
@ -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_buf_t wrbuf;
|
||||
int r;
|
||||
@ -164,12 +164,12 @@ static int after_write_called;
|
||||
static uv_pipe_t stdin_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(memcmp("hello world\n", buf.base, nread) == 0);
|
||||
ASSERT(memcmp("hello world\n", buf->base, nread) == 0);
|
||||
on_pipe_read_called++;
|
||||
|
||||
free(buf.base);
|
||||
free(buf->base);
|
||||
|
||||
uv_close((uv_handle_t*)&stdin_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*)&stdin_pipe);
|
||||
|
||||
r = uv_read_start((uv_stream_t*)&stdin_pipe, on_read_alloc,
|
||||
on_pipe_read);
|
||||
r = uv_read_start((uv_stream_t*)&stdin_pipe, on_read_alloc, on_pipe_read);
|
||||
ASSERT(r == 0);
|
||||
|
||||
uv_run(loop, UV_RUN_DEFAULT);
|
||||
|
||||
@ -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);
|
||||
|
||||
if (nread >= 0) {
|
||||
ASSERT(nread == 4);
|
||||
ASSERT(memcmp("PING", buf.base, nread) == 0);
|
||||
ASSERT(memcmp("PING", buf->base, nread) == 0);
|
||||
}
|
||||
else {
|
||||
ASSERT(nread == UV_EOF);
|
||||
|
||||
@ -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) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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");
|
||||
}
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@
|
||||
static void connection_cb(uv_stream_t* server, int status);
|
||||
static void connect_cb(uv_connect_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 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) {
|
||||
fprintf(stderr, "read_cb error: %s\n", uv_err_name(nread));
|
||||
ASSERT(nread == UV_ECONNRESET || nread == UV_EOF);
|
||||
|
||||
@ -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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
free(buf.base);
|
||||
free(buf->base);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user