mirror of
https://github.com/wez/wezterm.git
synced 2024-11-23 15:04:36 +03:00
introduce our own poll function
This is just a minor refactoring at this stage Refs https://github.com/wez/wezterm/issues/31
This commit is contained in:
parent
00c1000caa
commit
090c24554f
@ -8,6 +8,8 @@ use num::{self, NumCast};
|
||||
use std::fmt::Display;
|
||||
use std::time::Duration;
|
||||
|
||||
#[cfg(unix)]
|
||||
pub mod poll;
|
||||
#[cfg(unix)]
|
||||
pub mod unix;
|
||||
#[cfg(windows)]
|
||||
|
19
termwiz/src/terminal/poll.rs
Normal file
19
termwiz/src/terminal/poll.rs
Normal file
@ -0,0 +1,19 @@
|
||||
use libc::pollfd;
|
||||
use std::time::Duration;
|
||||
|
||||
pub fn poll(pfd: &mut [pollfd], duration: Option<Duration>) -> Result<usize, std::io::Error> {
|
||||
let poll_result = unsafe {
|
||||
libc::poll(
|
||||
pfd.as_mut_ptr(),
|
||||
pfd.len() as _,
|
||||
duration
|
||||
.map(|wait| wait.as_millis() as libc::c_int)
|
||||
.unwrap_or(-1),
|
||||
)
|
||||
};
|
||||
if poll_result < 0 {
|
||||
Err(std::io::Error::last_os_error())
|
||||
} else {
|
||||
Ok(poll_result as usize)
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
use failure::{bail, format_err, Error, Fallible};
|
||||
use filedescriptor::FileDescriptor;
|
||||
use libc::{self, poll, pollfd, winsize, POLLIN};
|
||||
use libc::{self, pollfd, winsize, POLLIN, POLLNVAL};
|
||||
use signal_hook::{self, SigId};
|
||||
use std::collections::VecDeque;
|
||||
use std::fs::OpenOptions;
|
||||
@ -415,17 +415,7 @@ impl Terminal for UnixTerminal {
|
||||
Blocking::DoNotWait
|
||||
})?;
|
||||
|
||||
let poll_result = unsafe {
|
||||
poll(
|
||||
pfd.as_mut_ptr(),
|
||||
pfd.len() as _,
|
||||
wait.map(|wait| wait.as_millis() as libc::c_int)
|
||||
.unwrap_or(-1),
|
||||
)
|
||||
};
|
||||
if poll_result < 0 {
|
||||
let err = IoError::last_os_error();
|
||||
|
||||
if let Err(err) = super::poll::poll(&mut pfd, wait) {
|
||||
if err.kind() == ErrorKind::Interrupted {
|
||||
// SIGWINCH may have been the source of the interrupt.
|
||||
// Check for that now so that we reduce the latency of
|
||||
@ -437,7 +427,7 @@ impl Terminal for UnixTerminal {
|
||||
return Ok(None);
|
||||
}
|
||||
return Err(format_err!("poll(2) error: {}", err));
|
||||
}
|
||||
};
|
||||
|
||||
if pfd[0].revents != 0 {
|
||||
// SIGWINCH received via our pipe?
|
||||
@ -448,6 +438,9 @@ impl Terminal for UnixTerminal {
|
||||
|
||||
if pfd[1].revents != 0 {
|
||||
let mut buf = [0u8; 64];
|
||||
if pfd[1].revents & POLLNVAL != 0 {
|
||||
bail!("poll reports POLLNVAL for tty input");
|
||||
}
|
||||
match self.read.read(&mut buf) {
|
||||
Ok(n) => {
|
||||
let input_queue = &mut self.input_queue;
|
||||
|
Loading…
Reference in New Issue
Block a user