ext/asyncengine/libuv/src/win/stream.c in asyncengine-0.0.1.testing1 vs ext/asyncengine/libuv/src/win/stream.c in asyncengine-0.0.2.alpha1

- old
+ new

@@ -20,40 +20,15 @@ */ #include <assert.h> #include "uv.h" -#include "../uv-common.h" #include "internal.h" +#include "handle-inl.h" +#include "req-inl.h" -void uv_stream_init(uv_loop_t* loop, uv_stream_t* handle) { - handle->write_queue_size = 0; - handle->loop = loop; - handle->flags = 0; - - loop->counters.handle_init++; - loop->counters.stream_init++; - - uv_ref(loop); -} - - -void uv_connection_init(uv_stream_t* handle) { - handle->flags |= UV_HANDLE_CONNECTION; - handle->write_reqs_pending = 0; - - uv_req_init(handle->loop, (uv_req_t*) &(handle->read_req)); - handle->read_req.event_handle = NULL; - handle->read_req.wait_handle = INVALID_HANDLE_VALUE; - handle->read_req.type = UV_READ; - handle->read_req.data = handle; - - handle->shutdown_req = NULL; -} - - int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb) { switch (stream->type) { case UV_TCP: return uv_tcp_listen((uv_tcp_t*)stream, backlog, cb); case UV_NAMED_PIPE: @@ -107,13 +82,16 @@ int uv_read_stop(uv_stream_t* handle) { if (handle->type == UV_TTY) { return uv_tty_read_stop((uv_tty_t*) handle); - } else { + } else if (handle->flags & UV_HANDLE_READING) { handle->flags &= ~UV_HANDLE_READING; + DECREASE_ACTIVE_COUNT(handle->loop, handle); return 0; + } else { + return 0; } } int uv_write(uv_write_t* req, uv_stream_t* handle, uv_buf_t bufs[], int bufcnt, @@ -169,33 +147,21 @@ req->cb = cb; handle->flags |= UV_HANDLE_SHUTTING; handle->shutdown_req = req; handle->reqs_pending++; - uv_ref(loop); + REGISTER_HANDLE_REQ(loop, handle, req); uv_want_endgame(loop, (uv_handle_t*)handle); return 0; } -size_t uv_count_bufs(uv_buf_t bufs[], int count) { - size_t bytes = 0; - int i; - - for (i = 0; i < count; i++) { - bytes += (size_t)bufs[i].len; - } - - return bytes; -} - - -int uv_is_readable(uv_stream_t* handle) { +int uv_is_readable(const uv_stream_t* handle) { return !(handle->flags & UV_HANDLE_EOF); } -int uv_is_writable(uv_stream_t* handle) { +int uv_is_writable(const uv_stream_t* handle) { return !(handle->flags & UV_HANDLE_SHUTTING); }