aboutsummaryrefslogtreecommitdiff
path: root/deps/uv/src/win/tty.c
diff options
context:
space:
mode:
Diffstat (limited to 'deps/uv/src/win/tty.c')
-rw-r--r--deps/uv/src/win/tty.c75
1 files changed, 38 insertions, 37 deletions
diff --git a/deps/uv/src/win/tty.c b/deps/uv/src/win/tty.c
index 64934ffa99..ee615295f9 100644
--- a/deps/uv/src/win/tty.c
+++ b/deps/uv/src/win/tty.c
@@ -24,7 +24,7 @@
#include <string.h>
#if defined(_MSC_VER) && _MSC_VER < 1600
-# include "uv-private/stdint-msvc2008.h"
+# include "stdint-msvc2008.h"
#else
# include <stdint.h>
#endif
@@ -101,15 +101,13 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, uv_file fd, int readable) {
handle = (HANDLE) _get_osfhandle(fd);
if (handle == INVALID_HANDLE_VALUE) {
- uv__set_artificial_error(loop, UV_EBADF);
- return -1;
+ return UV_EBADF;
}
if (!readable) {
/* Obtain the screen buffer info with the output handle. */
if (!GetConsoleScreenBufferInfo(handle, &screen_buffer_info)) {
- uv__set_sys_error(loop, GetLastError());
- return -1;
+ return uv_translate_sys_error(GetLastError());
}
/* Obtain the the tty_output_lock because the virtual window state is */
@@ -170,10 +168,10 @@ int uv_tty_set_mode(uv_tty_t* tty, int mode) {
unsigned char was_reading;
uv_alloc_cb alloc_cb;
uv_read_cb read_cb;
+ int err;
if (!(tty->flags & UV_HANDLE_TTY_READABLE)) {
- uv__set_artificial_error(tty->loop, UV_EINVAL);
- return -1;
+ return UV_EINVAL;
}
if (!!mode == !!(tty->flags & UV_HANDLE_TTY_RAW)) {
@@ -189,8 +187,7 @@ int uv_tty_set_mode(uv_tty_t* tty, int mode) {
}
if (!SetConsoleMode(tty->handle, flags)) {
- uv__set_sys_error(tty->loop, GetLastError());
- return -1;
+ return uv_translate_sys_error(GetLastError());
}
/* If currently reading, stop, and restart reading. */
@@ -199,8 +196,11 @@ int uv_tty_set_mode(uv_tty_t* tty, int mode) {
alloc_cb = tty->alloc_cb;
read_cb = tty->read_cb;
- if (was_reading && uv_tty_read_stop(tty) != 0) {
- return -1;
+ if (was_reading) {
+ err = uv_tty_read_stop(tty);
+ if (err) {
+ return uv_translate_sys_error(err);
+ }
}
} else {
was_reading = 0;
@@ -211,8 +211,11 @@ int uv_tty_set_mode(uv_tty_t* tty, int mode) {
tty->flags |= mode ? UV_HANDLE_TTY_RAW : 0;
/* If we just stopped reading, restart. */
- if (was_reading && uv_tty_read_start(tty, alloc_cb, read_cb) != 0) {
- return -1;
+ if (was_reading) {
+ err = uv_tty_read_start(tty, alloc_cb, read_cb);
+ if (err) {
+ return uv_translate_sys_error(err);
+ }
}
return 0;
@@ -229,8 +232,7 @@ int uv_tty_get_winsize(uv_tty_t* tty, int* width, int* height) {
CONSOLE_SCREEN_BUFFER_INFO info;
if (!GetConsoleScreenBufferInfo(tty->handle, &info)) {
- uv__set_sys_error(tty->loop, GetLastError());
- return -1;
+ return uv_translate_sys_error(GetLastError());
}
EnterCriticalSection(&uv_tty_output_lock);
@@ -479,18 +481,20 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
/* An error occurred while waiting for the event. */
if ((handle->flags & UV_HANDLE_READING)) {
handle->flags &= ~UV_HANDLE_READING;
- uv__set_sys_error(loop, GET_REQ_ERROR(req));
- handle->read_cb((uv_stream_t*)handle, -1, uv_null_buf_);
+ handle->read_cb((uv_stream_t*)handle,
+ uv_translate_sys_error(GET_REQ_ERROR(req)),
+ uv_null_buf_);
}
goto out;
}
/* Fetch the number of events */
if (!GetNumberOfConsoleInputEvents(handle->handle, &records_left)) {
- uv__set_sys_error(loop, GetLastError());
handle->flags &= ~UV_HANDLE_READING;
DECREASE_ACTIVE_COUNT(loop, handle);
- handle->read_cb((uv_stream_t*)handle, -1, uv_null_buf_);
+ handle->read_cb((uv_stream_t*)handle,
+ uv_translate_sys_error(GetLastError()),
+ uv_null_buf_);
goto out;
}
@@ -507,10 +511,11 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
&handle->last_input_record,
1,
&records_read)) {
- uv__set_sys_error(loop, GetLastError());
handle->flags &= ~UV_HANDLE_READING;
DECREASE_ACTIVE_COUNT(loop, handle);
- handle->read_cb((uv_stream_t*) handle, -1, buf);
+ handle->read_cb((uv_stream_t*) handle,
+ uv_translate_sys_error(GetLastError()),
+ buf);
goto out;
}
records_left--;
@@ -626,10 +631,11 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
/* If the utf16 character(s) couldn't be converted something must */
/* be wrong. */
if (!char_len) {
- uv__set_sys_error(loop, GetLastError());
handle->flags &= ~UV_HANDLE_READING;
DECREASE_ACTIVE_COUNT(loop, handle);
- handle->read_cb((uv_stream_t*) handle, -1, buf);
+ handle->read_cb((uv_stream_t*) handle,
+ uv_translate_sys_error(GetLastError()),
+ buf);
goto out;
}
@@ -739,11 +745,11 @@ void uv_process_tty_read_line_req(uv_loop_t* loop, uv_tty_t* handle,
/* Real error */
handle->flags &= ~UV_HANDLE_READING;
DECREASE_ACTIVE_COUNT(loop, handle);
- uv__set_sys_error(loop, GET_REQ_ERROR(req));
- handle->read_cb((uv_stream_t*) handle, -1, buf);
+ handle->read_cb((uv_stream_t*) handle,
+ uv_translate_sys_error(GET_REQ_ERROR(req)),
+ buf);
} else {
/* The read was cancelled, or whatever we don't care */
- uv__set_sys_error(loop, WSAEWOULDBLOCK); /* maps to UV_EAGAIN */
handle->read_cb((uv_stream_t*) handle, 0, buf);
}
@@ -751,9 +757,6 @@ void uv_process_tty_read_line_req(uv_loop_t* loop, uv_tty_t* handle,
/* Read successful */
/* TODO: read unicode, convert to utf-8 */
DWORD bytes = req->overlapped.InternalHigh;
- if (bytes == 0) {
- uv__set_sys_error(loop, WSAEWOULDBLOCK); /* maps to UV_EAGAIN */
- }
handle->read_cb((uv_stream_t*) handle, bytes, buf);
}
@@ -788,8 +791,7 @@ int uv_tty_read_start(uv_tty_t* handle, uv_alloc_cb alloc_cb,
uv_loop_t* loop = handle->loop;
if (!(handle->flags & UV_HANDLE_TTY_READABLE)) {
- uv__set_artificial_error(handle->loop, UV_EINVAL);
- return -1;
+ return ERROR_INVALID_PARAMETER;
}
handle->flags |= UV_HANDLE_READING;
@@ -831,8 +833,7 @@ int uv_tty_read_stop(uv_tty_t* handle) {
DWORD written;
memset(&record, 0, sizeof record);
if (!WriteConsoleInputW(handle->handle, &record, 1, &written)) {
- uv__set_sys_error(loop, GetLastError());
- return -1;
+ return GetLastError();
}
}
@@ -1763,13 +1764,14 @@ int uv_tty_write(uv_loop_t* loop, uv_write_t* req, uv_tty_t* handle,
void uv_process_tty_write_req(uv_loop_t* loop, uv_tty_t* handle,
uv_write_t* req) {
+ int err;
handle->write_queue_size -= req->queued_bytes;
UNREGISTER_HANDLE_REQ(loop, handle, req);
if (req->cb) {
- uv__set_sys_error(loop, GET_REQ_ERROR(req));
- ((uv_write_cb)req->cb)(req, loop->last_err.code == UV_OK ? 0 : -1);
+ err = GET_REQ_ERROR(req);
+ req->cb(req, uv_translate_sys_error(err));
}
handle->write_reqs_pending--;
@@ -1806,8 +1808,7 @@ void uv_tty_endgame(uv_loop_t* loop, uv_tty_t* handle) {
/* TTY shutdown is really just a no-op */
if (handle->shutdown_req->cb) {
if (handle->flags & UV__HANDLE_CLOSING) {
- uv__set_artificial_error(loop, UV_ECANCELED);
- handle->shutdown_req->cb(handle->shutdown_req, -1);
+ handle->shutdown_req->cb(handle->shutdown_req, UV_ECANCELED);
} else {
handle->shutdown_req->cb(handle->shutdown_req, 0);
}