1
1
mirror of https://github.com/wez/wezterm.git synced 2024-09-20 19:27:22 +03:00

fix pollable_channel to be non-blocking on Windows

Upgrade filedescriptor to 0.7 to use the portable helper for
setting non-blocking mode, and enable non-blocking mode on Windows.
This commit is contained in:
Wez Furlong 2020-01-15 21:30:14 -08:00
parent 101aedd6a5
commit 256b4e6da8
9 changed files with 19 additions and 38 deletions

12
Cargo.lock generated
View File

@ -719,7 +719,7 @@ dependencies = [
[[package]]
name = "filedescriptor"
version = "0.6.0"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"anyhow 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1739,7 +1739,7 @@ version = "0.2.0"
dependencies = [
"anyhow 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"filedescriptor 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"filedescriptor 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2509,7 +2509,7 @@ dependencies = [
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cassowary 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"derive_builder 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"filedescriptor 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"filedescriptor 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2836,7 +2836,7 @@ dependencies = [
"euclid 0.20.7 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"filedescriptor 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"filedescriptor 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"font-kit 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"font-loader 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"fontconfig 0.1.0",
@ -2944,7 +2944,7 @@ dependencies = [
"core-foundation 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"core-graphics 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.20.7 (registry+https://github.com/rust-lang/crates.io-index)",
"filedescriptor 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"filedescriptor 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gl_generator 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
"glium 0.26.0-alpha6 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3187,7 +3187,7 @@ dependencies = [
"checksum expat-sys 2.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "658f19728920138342f68408b7cf7644d90d4784353d8ebc32e7e8663dbe45fa"
"checksum failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f8273f13c977665c5db7eb2b99ae520952fe5ac831ae4cd09d80c4c7042b5ed9"
"checksum failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0bc225b78e0391e4b8683440bf2e63c2deeeb2ce5189eab46e2b68c6d3725d08"
"checksum filedescriptor 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "08f0c21550f7dab3f61284df9ad7fbd094c667daa33fac908e90e168cb0ff9b7"
"checksum filedescriptor 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2635e33a91cc1551a5e6b0e7386529add2874da81ed0db79134a2c2ad65b3efb"
"checksum filetime 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1ff6d4dab0aa0c8e6346d46052e93b13a16cf847b54ed357087c35011048cc7d"
"checksum flate2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6bd6d6f4752952feb71363cffc9ebac9411b75b87c6ab6058c40c8900cf43c0f"
"checksum float-ord 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7bad48618fdb549078c333a7a8528acb57af271d0433bdecd523eb620628364e"

View File

@ -23,7 +23,7 @@ crossbeam-channel = "0.3"
dirs = "1.0"
downcast-rs = "1.0"
euclid = "0.20"
filedescriptor = "0.6"
filedescriptor = "0.7"
pretty_env_logger = "0.3"
failure = "0.1"
failure_derive = "0.1"

View File

@ -10,7 +10,7 @@ documentation = "https://docs.rs/portable-pty"
[dependencies]
anyhow = "1.0"
filedescriptor = "0.6"
filedescriptor = "0.7"
log = "0.4"
libc = "0.2"
shell-words = "0.1"

View File

@ -97,14 +97,10 @@ impl<T> AsPollFd for PollableReceiver<T> {
/// windows 10 w/unix domain socket support.
pub fn pollable_channel<T>() -> anyhow::Result<(PollableSender<T>, PollableReceiver<T>)> {
let (sender, receiver) = channel();
let (write, read) = socketpair()?;
let (mut write, mut read) = socketpair()?;
#[cfg(unix)]
unsafe {
let on = 1;
libc::ioctl(write.as_raw_file_descriptor(), libc::FIONBIO, &on);
libc::ioctl(read.as_raw_file_descriptor(), libc::FIONBIO, &on);
}
write.set_non_blocking(true)?;
read.set_non_blocking(true)?;
Ok((
PollableSender {

View File

@ -16,7 +16,7 @@ bitflags = "1.0"
cassowary = {version="0.3", optional=true}
derive_builder = "0.7"
anyhow = "1.0"
filedescriptor = "0.6"
filedescriptor = "0.7"
fnv = {version="1.0", optional=true}
libc = "0.2"
log = "0.4"

View File

@ -60,13 +60,7 @@ impl TtyReadHandle {
}
fn set_blocking(&mut self, blocking: Blocking) -> Result<(), Error> {
let value: libc::c_int = match blocking {
Blocking::Wait => 0,
Blocking::DoNotWait => 1,
};
if unsafe { libc::ioctl(self.fd.as_raw_fd(), libc::FIONBIO, &value as *const _) } != 0 {
bail!("failed to ioctl(FIONBIO): {:?}", IoError::last_os_error());
}
self.fd.set_non_blocking(blocking == Blocking::DoNotWait)?;
Ok(())
}
}

View File

@ -47,7 +47,7 @@ winapi = { version = "0.3", features = [
clipboard-win = "2.2"
[target.'cfg(all(unix, not(target_os = "macos")))'.dependencies]
filedescriptor = "0.6"
filedescriptor = "0.7"
x11 = {version ="2.18", features = ["xlib_xcb"]}
xcb = "0.8"
# See: https://github.com/meh/rust-xcb-util/issues/12

View File

@ -813,10 +813,7 @@ impl WindowOps for WaylandWindow {
}
fn write_pipe_with_timeout(mut file: FileDescriptor, data: &[u8]) -> anyhow::Result<()> {
let on: libc::c_int = 1;
unsafe {
libc::ioctl(file.as_raw_fd(), libc::FIONBIO, &on);
}
file.set_non_blocking(true)?;
let mut pfd = libc::pollfd {
fd: file.as_raw_fd(),
events: libc::POLLOUT,
@ -847,10 +844,7 @@ fn write_pipe_with_timeout(mut file: FileDescriptor, data: &[u8]) -> anyhow::Res
fn read_pipe_with_timeout(mut file: FileDescriptor) -> anyhow::Result<String> {
let mut result = Vec::new();
let on: libc::c_int = 1;
unsafe {
libc::ioctl(file.as_raw_fd(), libc::FIONBIO, &on);
}
file.set_non_blocking(true)?;
let mut pfd = libc::pollfd {
fd: file.as_raw_fd(),
events: libc::POLLIN,

View File

@ -123,12 +123,9 @@ impl SpawnQueue {
// We can't affort to use a blocking pipe for the wakeup
// because the write needs to hold a mutex and that
// can block reads as well as other writers.
let pipe = Pipe::new().map_err(anyhow::Error::msg)?;
let on = 1;
unsafe {
libc::ioctl(pipe.write.as_raw_fd(), libc::FIONBIO, &on);
libc::ioctl(pipe.read.as_raw_fd(), libc::FIONBIO, &on);
}
let mut pipe = Pipe::new()?;
pipe.write.set_non_blocking(true)?;
pipe.read.set_non_blocking(true)?;
Ok(Self {
spawned_funcs: Mutex::new(VecDeque::new()),
spawned_funcs_low_pri: Mutex::new(VecDeque::new()),