Commit
These flags supersede UV_HANDLE_EOF and UV_HANDLE_SHUTTING. This patch also moves a lot of stream related state-checking code to stream.c.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,16 @@ int uv_accept(uv_stream_t* server, uv_stream_t* client) { | |
|
||
int uv_read_start(uv_stream_t* handle, uv_alloc_cb alloc_cb, | ||
uv_read_cb read_cb) { | ||
if (handle->flags & UV_HANDLE_READING) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
piscisaureus
Author
|
||
uv__set_sys_error(handle->loop, UV_EALREADY); | ||
return -1; | ||
} | ||
|
||
if (!(handle->flags & UV_HANDLE_READABLE)) { | ||
uv__set_artificial_error(handle->loop, UV_ENOTCONN); | ||
return -1; | ||
} | ||
|
||
switch (handle->type) { | ||
case UV_TCP: | ||
return uv_tcp_read_start((uv_tcp_t*)handle, alloc_cb, read_cb); | ||
|
@@ -71,6 +81,16 @@ int uv_read_start(uv_stream_t* handle, uv_alloc_cb alloc_cb, | |
|
||
int uv_read2_start(uv_stream_t* handle, uv_alloc_cb alloc_cb, | ||
uv_read2_cb read_cb) { | ||
if (handle->flags & UV_HANDLE_READING) { | ||
uv__set_sys_error(handle->loop, UV_EALREADY); | ||
return -1; | ||
} | ||
|
||
if (!(handle->flags & UV_HANDLE_READABLE)) { | ||
uv__set_artificial_error(handle->loop, UV_ENOTCONN); | ||
return -1; | ||
} | ||
|
||
switch (handle->type) { | ||
case UV_NAMED_PIPE: | ||
return uv_pipe_read2_start((uv_pipe_t*)handle, alloc_cb, read_cb); | ||
|
@@ -82,14 +102,15 @@ int uv_read2_start(uv_stream_t* handle, uv_alloc_cb alloc_cb, | |
|
||
|
||
int uv_read_stop(uv_stream_t* handle) { | ||
if (!(handle->flags & UV_HANDLE_READING)) | ||
return 0; | ||
|
||
if (handle->type == UV_TTY) { | ||
return uv_tty_read_stop((uv_tty_t*) handle); | ||
} else if (handle->flags & UV_HANDLE_READING) { | ||
} else { | ||
handle->flags &= ~UV_HANDLE_READING; | ||
DECREASE_ACTIVE_COUNT(handle->loop, handle); | ||
return 0; | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
|
@@ -98,6 +119,11 @@ int uv_write(uv_write_t* req, uv_stream_t* handle, uv_buf_t bufs[], int bufcnt, | |
uv_write_cb cb) { | ||
uv_loop_t* loop = handle->loop; | ||
|
||
if (!(handle->flags & UV_HANDLE_WRITABLE)) { | ||
uv__set_artificial_error(loop, UV_EPIPE); | ||
return -1; | ||
} | ||
|
||
switch (handle->type) { | ||
case UV_TCP: | ||
return uv_tcp_write(loop, req, (uv_tcp_t*) handle, bufs, bufcnt, cb); | ||
|
@@ -117,6 +143,11 @@ int uv_write2(uv_write_t* req, uv_stream_t* handle, uv_buf_t bufs[], int bufcnt, | |
uv_stream_t* send_handle, uv_write_cb cb) { | ||
uv_loop_t* loop = handle->loop; | ||
|
||
if (!(handle->flags & UV_HANDLE_WRITABLE)) { | ||
uv__set_artificial_error(loop, UV_EPIPE); | ||
return -1; | ||
} | ||
|
||
switch (handle->type) { | ||
case UV_NAMED_PIPE: | ||
return uv_pipe_write2(loop, req, (uv_pipe_t*) handle, bufs, bufcnt, send_handle, cb); | ||
|
@@ -131,13 +162,13 @@ int uv_write2(uv_write_t* req, uv_stream_t* handle, uv_buf_t bufs[], int bufcnt, | |
int uv_shutdown(uv_shutdown_t* req, uv_stream_t* handle, uv_shutdown_cb cb) { | ||
uv_loop_t* loop = handle->loop; | ||
|
||
if (!(handle->flags & UV_HANDLE_CONNECTION)) { | ||
uv__set_sys_error(loop, WSAEINVAL); | ||
if (!(handle->flags & UV_HANDLE_WRITABLE)) { | ||
uv__set_artificial_error(loop, UV_EPIPE); | ||
return -1; | ||
} | ||
|
||
if (handle->flags & UV_HANDLE_SHUTTING) { | ||
uv__set_sys_error(loop, WSAESHUTDOWN); | ||
if (!(handle->flags & UV_HANDLE_WRITABLE)) { | ||
uv__set_artificial_error(loop, UV_EPIPE); | ||
return -1; | ||
} | ||
|
||
|
@@ -146,7 +177,7 @@ int uv_shutdown(uv_shutdown_t* req, uv_stream_t* handle, uv_shutdown_cb cb) { | |
req->handle = handle; | ||
req->cb = cb; | ||
|
||
handle->flags |= UV_HANDLE_SHUTTING; | ||
handle->flags &= ~UV_HANDLE_WRITABLE; | ||
handle->shutdown_req = req; | ||
handle->reqs_pending++; | ||
REGISTER_HANDLE_REQ(loop, handle, req); | ||
|
@@ -158,10 +189,10 @@ int uv_shutdown(uv_shutdown_t* req, uv_stream_t* handle, uv_shutdown_cb cb) { | |
|
||
|
||
int uv_is_readable(const uv_stream_t* handle) { | ||
return !(handle->flags & UV_HANDLE_EOF); | ||
return !!(handle->flags & UV_HANDLE_READABLE); | ||
} | ||
|
||
|
||
int uv_is_writable(const uv_stream_t* handle) { | ||
return !(handle->flags & UV_HANDLE_SHUTTING); | ||
return !!(handle->flags & UV_HANDLE_WRITABLE); | ||
} |
The unix version doesn't seem to do this, it seems to allow multiple calls to uv_read_start. Is this a bug or a feature? :-)