diff options
author | Bert Belder <bertbelder@gmail.com> | 2021-01-14 20:32:27 -0800 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2021-01-29 01:35:07 -0800 |
commit | 98878bd81231a631c494b6767576097f945eb813 (patch) | |
tree | f66f027cf9692548696a7ce5417fba60cec51f60 /runtime/ops/tty.rs | |
parent | c8a5e3c1e485915880bd5ed10438ac87baf4a80b (diff) |
refactor: IO resource types, fix concurrent read/write and graceful close (#9118)
Fixes: 9032.
Diffstat (limited to 'runtime/ops/tty.rs')
-rw-r--r-- | runtime/ops/tty.rs | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/runtime/ops/tty.rs b/runtime/ops/tty.rs index dfde8e0d3..a8ff9938b 100644 --- a/runtime/ops/tty.rs +++ b/runtime/ops/tty.rs @@ -1,7 +1,6 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -use super::io::std_file_resource; -use super::io::StreamResource; +use super::io::StdFileResource; use deno_core::error::bad_resource_id; use deno_core::error::not_supported; use deno_core::error::resource_unavailable; @@ -90,7 +89,7 @@ fn op_set_raw( let resource = state .resource_table - .get::<StreamResource>(rid) + .get::<StdFileResource>(rid) .ok_or_else(bad_resource_id)?; if cbreak { @@ -157,7 +156,7 @@ fn op_set_raw( let resource = state .resource_table - .get::<StreamResource>(rid) + .get::<StdFileResource>(rid) .ok_or_else(bad_resource_id)?; if resource.fs_file.is_none() { @@ -229,26 +228,27 @@ fn op_isatty( let args: IsattyArgs = serde_json::from_value(args)?; let rid = args.rid; - let isatty: bool = std_file_resource(state, rid as u32, move |r| match r { - Ok(std_file) => { - #[cfg(windows)] - { - use winapi::um::consoleapi; - - let handle = get_windows_handle(&std_file)?; - let mut test_mode: DWORD = 0; - // If I cannot get mode out of console, it is not a console. - Ok(unsafe { consoleapi::GetConsoleMode(handle, &mut test_mode) != 0 }) - } - #[cfg(unix)] - { - use std::os::unix::io::AsRawFd; - let raw_fd = std_file.as_raw_fd(); - Ok(unsafe { libc::isatty(raw_fd as libc::c_int) == 1 }) + let isatty: bool = + StdFileResource::with(state, rid as u32, move |r| match r { + Ok(std_file) => { + #[cfg(windows)] + { + use winapi::um::consoleapi; + + let handle = get_windows_handle(&std_file)?; + let mut test_mode: DWORD = 0; + // If I cannot get mode out of console, it is not a console. + Ok(unsafe { consoleapi::GetConsoleMode(handle, &mut test_mode) != 0 }) + } + #[cfg(unix)] + { + use std::os::unix::io::AsRawFd; + let raw_fd = std_file.as_raw_fd(); + Ok(unsafe { libc::isatty(raw_fd as libc::c_int) == 1 }) + } } - } - _ => Ok(false), - })?; + _ => Ok(false), + })?; Ok(json!(isatty)) } @@ -273,7 +273,7 @@ fn op_console_size( let args: ConsoleSizeArgs = serde_json::from_value(args)?; let rid = args.rid; - let size = std_file_resource(state, rid as u32, move |r| match r { + let size = StdFileResource::with(state, rid as u32, move |r| match r { Ok(std_file) => { #[cfg(windows)] { |