diff --git a/include/uv.h b/include/uv.h index cde05cb9b..4ee43bce5 100644 --- a/include/uv.h +++ b/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); diff --git a/src/unix/stream.c b/src/unix/stream.c index ab030a795..aa49c21bf 100644 --- a/src/unix/stream.c +++ b/src/unix/stream.c @@ -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) diff --git a/src/win/pipe.c b/src/win/pipe.c index 5e73cb9e2..09b59cc65 100644 --- a/src/win/pipe.c +++ b/src/win/pipe.c @@ -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 */ diff --git a/src/win/tcp.c b/src/win/tcp.c index 7b653175b..7bc1a0244 100644 --- a/src/win/tcp.c +++ b/src/win/tcp.c @@ -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; } diff --git a/src/win/tty.c b/src/win/tty.c index b3eea839a..60c301480 100644 --- a/src/win/tty.c +++ b/src/win/tty.c @@ -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. */ diff --git a/test/benchmark-multi-accept.c b/test/benchmark-multi-accept.c index 72ca1fa32..91571450b 100644 --- a/test/benchmark-multi-accept.c +++ b/test/benchmark-multi-accept.c @@ -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); } diff --git a/test/benchmark-ping-pongs.c b/test/benchmark-ping-pongs.c index daa145386..982e41eb5 100644 --- a/test/benchmark-ping-pongs.c +++ b/test/benchmark-ping-pongs.c @@ -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++; diff --git a/test/benchmark-pound.c b/test/benchmark-pound.c index 555a5283a..23ee51ef0 100644 --- a/test/benchmark-pound.c +++ b/test/benchmark-pound.c @@ -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); diff --git a/test/benchmark-pump.c b/test/benchmark-pump.c index 1d0a058ad..e08850d8c 100644 --- a/test/benchmark-pump.c +++ b/test/benchmark-pump.c @@ -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; } diff --git a/test/benchmark-spawn.c b/test/benchmark-spawn.c index 683e9b11a..30bc328be 100644 --- a/test/benchmark-spawn.c +++ b/test/benchmark-spawn.c @@ -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; diff --git a/test/blackhole-server.c b/test/blackhole-server.c index 2ff50b6c5..47dcebdf2 100644 --- a/test/blackhole-server.c +++ b/test/blackhole-server.c @@ -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; diff --git a/test/dns-server.c b/test/dns-server.c index ebeb933d5..6bb807e26 100644 --- a/test/dns-server.c +++ b/test/dns-server.c @@ -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 */ diff --git a/test/echo-server.c b/test/echo-server.c index 71c116228..4f349a0e7 100644 --- a/test/echo-server.c +++ b/test/echo-server.c @@ -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"); } diff --git a/test/test-callback-stack.c b/test/test-callback-stack.c index 7e848e805..8ac30f89f 100644 --- a/test/test-callback-stack.c +++ b/test/test-callback-stack.c @@ -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; diff --git a/test/test-delayed-accept.c b/test/test-delayed-accept.c index 937b47c2c..15ea093f3 100644 --- a/test/test-delayed-accept.c +++ b/test/test-delayed-accept.c @@ -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) { diff --git a/test/test-getsockname.c b/test/test-getsockname.c index 0c9b6a60e..e447906bf 100644 --- a/test/test-getsockname.c +++ b/test/test-getsockname.c @@ -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); diff --git a/test/test-ipc-send-recv.c b/test/test-ipc-send-recv.c index 36895573d..ab52b0c9e 100644 --- a/test/test-ipc-send-recv.c +++ b/test/test-ipc-send-recv.c @@ -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); diff --git a/test/test-ipc.c b/test/test-ipc.c index 95e8e7699..88bc1c339 100644 --- a/test/test-ipc.c +++ b/test/test-ipc.c @@ -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); diff --git a/test/test-osx-select.c b/test/test-osx-select.c index 26a867517..e5e1bf8b4 100644 --- a/test/test-osx-select.c +++ b/test/test-osx-select.c @@ -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) diff --git a/test/test-ping-pong.c b/test/test-ping-pong.c index ee605e5fc..856fc9454 100644 --- a/test/test-ping-pong.c +++ b/test/test-ping-pong.c @@ -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); } diff --git a/test/test-shutdown-eof.c b/test/test-shutdown-eof.c index 6b9da3723..ed9f3fbe6 100644 --- a/test/test-shutdown-eof.c +++ b/test/test-shutdown-eof.c @@ -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"); diff --git a/test/test-spawn.c b/test/test-spawn.c index 16a9ece65..0646dcb88 100644 --- a/test/test-spawn.c +++ b/test/test-spawn.c @@ -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) { diff --git a/test/test-stdio-over-pipes.c b/test/test-stdio-over-pipes.c index 38c816c0b..2a8283aca 100644 --- a/test/test-stdio-over-pipes.c +++ b/test/test-stdio-over-pipes.c @@ -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); diff --git a/test/test-tcp-open.c b/test/test-tcp-open.c index 7e106134f..89135dfd0 100644 --- a/test/test-tcp-open.c +++ b/test/test-tcp-open.c @@ -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); diff --git a/test/test-tcp-shutdown-after-write.c b/test/test-tcp-shutdown-after-write.c index 1c4f29bc8..5359d93b1 100644 --- a/test/test-tcp-shutdown-after-write.c +++ b/test/test-tcp-shutdown-after-write.c @@ -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) { } diff --git a/test/test-tcp-unexpected-read.c b/test/test-tcp-unexpected-read.c index 6197f7868..6ae3d4278 100644 --- a/test/test-tcp-unexpected-read.c +++ b/test/test-tcp-unexpected-read.c @@ -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"); } diff --git a/test/test-tcp-write-to-half-open-connection.c b/test/test-tcp-write-to-half-open-connection.c index 5546d86ec..0a04f3d1d 100644 --- a/test/test-tcp-write-to-half-open-connection.c +++ b/test/test-tcp-write-to-half-open-connection.c @@ -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); diff --git a/test/test-tcp-writealot.c b/test/test-tcp-writealot.c index 8005de919..2517df4b2 100644 --- a/test/test-tcp-writealot.c +++ b/test/test-tcp-writealot.c @@ -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); }