1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-22 04:56:12 +03:00

fix filedescriptor::poll on macos

Need to use the subsecond microsecond value, rather than the total
microsecond value, otherwise `select(2)` will yield EINVAL.

The wezterm changes show where this error was bubbling up
and breaking the tls client code.
This commit is contained in:
Wez Furlong 2020-09-10 13:58:14 -07:00
parent 6430952d74
commit aae287c4f2
5 changed files with 19 additions and 11 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "filedescriptor"
version = "0.7.2"
version = "0.7.3"
authors = ["Wez Furlong"]
edition = "2018"
repository = "https://github.com/wez/wezterm"

View File

@ -440,7 +440,7 @@ mod macos {
let mut timeout = duration.map(|d| timeval {
tv_sec: d.as_secs() as _,
tv_usec: d.as_micros() as _,
tv_usec: d.subsec_micros() as _,
});
let res = unsafe {

View File

@ -11,7 +11,7 @@ use crate::server::UnixStream;
use crate::ssh::ssh_connect_with_ui;
use anyhow::{anyhow, bail, Context, Error};
use crossbeam::channel::TryRecvError;
use filedescriptor::{pollfd, AsRawSocketDescriptor};
use filedescriptor::{poll, pollfd, AsRawSocketDescriptor};
use log::info;
use openssl::ssl::{SslConnector, SslFiletype, SslMethod};
use openssl::x509::X509;
@ -174,7 +174,17 @@ fn client_thread(
let mut poll_array = [rx.as_poll_fd(), reconnectable.stream().as_poll_fd()];
if !reconnectable.stream().has_read_buffered() {
poll_for_read(&mut poll_array);
if let Err(err) = poll(
&mut poll_array,
Some(std::time::Duration::from_millis(1000)),
) {
let reason = format!("Error while polling: {} {:?}", err, poll_array);
log::error!("{}", reason);
for (_, mut promise) in promises.into_iter() {
promise.result(Err(anyhow!("{}", reason)));
}
return Err(err).context("Error while polling");
}
}
if poll_array[1].revents != 0 || reconnectable.stream().has_read_buffered() {

View File

@ -4,6 +4,7 @@ use crate::server::listener::sessionhandler::SessionHandler;
use crate::server::pollable::*;
use anyhow::{bail, Context, Error};
use crossbeam::channel::TryRecvError;
use filedescriptor::poll;
use log::error;
use std::collections::HashSet;
@ -71,7 +72,10 @@ impl<S: ReadAndWrite> ClientSession<S> {
self.stream.as_poll_fd(),
self.mux_rx.as_poll_fd(),
];
poll_for_read(&mut poll_array);
poll(
&mut poll_array,
Some(std::time::Duration::from_millis(1000)),
)?;
if poll_array[1].revents != 0 || self.stream.has_read_buffered() {
loop {

View File

@ -129,9 +129,3 @@ impl AsPollFd for UnixStream {
self.as_socket_descriptor().as_poll_fd()
}
}
pub fn poll_for_read(pfd: &mut [pollfd]) {
if let Err(e) = poll(pfd, Some(std::time::Duration::from_millis(1000))) {
log::error!("poll failed for {}", e);
}
}