tty, win: fix read stop for raw mode
New Windows version requires `EventType` to be set to something meaningful, otherwise WriteConsoleInputW() will fail with `ERROR_INVALID_PARAMETER`. This sets it to `FOCUS_EVENT` which is ignored by `uv_process_tty_read_raw_req()`. Fixes: https://github.com/nodejs/node/issues/21773 PR-URL: https://github.com/libuv/libuv/pull/1989 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jameson Nash <vtjnash@gmail.com>
This commit is contained in:
parent
4bd01873eb
commit
b9a0840307
@ -1033,6 +1033,7 @@ int uv_tty_read_stop(uv_tty_t* handle) {
|
||||
/* Cancel raw read. Write some bullshit event to force the console wait to
|
||||
* return. */
|
||||
memset(&record, 0, sizeof record);
|
||||
record.EventType = FOCUS_EVENT;
|
||||
if (!WriteConsoleInputW(handle->handle, &record, 1, &written)) {
|
||||
return GetLastError();
|
||||
}
|
||||
|
||||
@ -50,6 +50,7 @@ TEST_DECLARE (tty)
|
||||
TEST_DECLARE (tty_raw)
|
||||
TEST_DECLARE (tty_empty_write)
|
||||
TEST_DECLARE (tty_large_write)
|
||||
TEST_DECLARE (tty_raw_cancel)
|
||||
#endif
|
||||
TEST_DECLARE (tty_file)
|
||||
TEST_DECLARE (tty_pty)
|
||||
@ -480,6 +481,7 @@ TASK_LIST_START
|
||||
TEST_ENTRY (tty_raw)
|
||||
TEST_ENTRY (tty_empty_write)
|
||||
TEST_ENTRY (tty_large_write)
|
||||
TEST_ENTRY (tty_raw_cancel)
|
||||
#endif
|
||||
TEST_ENTRY (tty_file)
|
||||
TEST_ENTRY (tty_pty)
|
||||
|
||||
@ -310,6 +310,41 @@ TEST_IMPL(tty_large_write) {
|
||||
MAKE_VALGRIND_HAPPY();
|
||||
return 0;
|
||||
}
|
||||
|
||||
TEST_IMPL(tty_raw_cancel) {
|
||||
int r;
|
||||
int ttyin_fd;
|
||||
uv_tty_t tty_in;
|
||||
uv_loop_t* loop;
|
||||
HANDLE handle;
|
||||
|
||||
loop = uv_default_loop();
|
||||
/* Make sure we have an FD that refers to a tty */
|
||||
handle = CreateFileA("conin$",
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
NULL);
|
||||
ASSERT(handle != INVALID_HANDLE_VALUE);
|
||||
ttyin_fd = _open_osfhandle((intptr_t) handle, 0);
|
||||
ASSERT(ttyin_fd >= 0);
|
||||
ASSERT(UV_TTY == uv_guess_handle(ttyin_fd));
|
||||
|
||||
r = uv_tty_init(uv_default_loop(), &tty_in, ttyin_fd, 1); /* Readable. */
|
||||
ASSERT(r == 0);
|
||||
r = uv_tty_set_mode(&tty_in, UV_TTY_MODE_RAW);
|
||||
ASSERT(r == 0);
|
||||
r = uv_read_start((uv_stream_t*)&tty_in, tty_raw_alloc, tty_raw_read);
|
||||
ASSERT(r == 0);
|
||||
|
||||
r = uv_read_stop((uv_stream_t*) &tty_in);
|
||||
ASSERT(r == 0);
|
||||
|
||||
MAKE_VALGRIND_HAPPY();
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user