From c2f8abecfbaf6b6388e7746b733b7f22cbb7a750 Mon Sep 17 00:00:00 2001 From: John Nunley Date: Sat, 7 Oct 2023 12:56:11 -0700 Subject: Port from mio to polling This patch replaces the mio crate with the polling. Now that smol-rs/polling#96 has been merged, we should be at full feature parity with mio v0.6 now. Fixes #7104. Fixes #6486. --- alacritty_terminal/src/tty/windows/mod.rs | 112 ++++++++++-------------------- 1 file changed, 35 insertions(+), 77 deletions(-) (limited to 'alacritty_terminal/src/tty/windows/mod.rs') diff --git a/alacritty_terminal/src/tty/windows/mod.rs b/alacritty_terminal/src/tty/windows/mod.rs index 57925f4c..080f6e83 100644 --- a/alacritty_terminal/src/tty/windows/mod.rs +++ b/alacritty_terminal/src/tty/windows/mod.rs @@ -3,17 +3,27 @@ use std::io::{self, Error, ErrorKind, Result}; use std::iter::once; use std::os::windows::ffi::OsStrExt; use std::sync::mpsc::TryRecvError; +use std::sync::Arc; use crate::config::{Program, PtyConfig}; use crate::event::{OnResize, WindowSize}; use crate::tty::windows::child::ChildExitWatcher; use crate::tty::{ChildEvent, EventedPty, EventedReadWrite}; +mod blocking; mod child; mod conpty; +use blocking::{UnblockedReader, UnblockedWriter}; use conpty::Conpty as Backend; -use mio_anonymous_pipes::{EventedAnonRead as ReadPipe, EventedAnonWrite as WritePipe}; +use miow::pipe::{AnonRead, AnonWrite}; +use polling::{Event, Poller}; + +pub const PTY_CHILD_EVENT_TOKEN: usize = 1; +pub const PTY_READ_WRITE_TOKEN: usize = 2; + +type ReadPipe = UnblockedReader; +type WritePipe = UnblockedWriter; pub struct Pty { // XXX: Backend is required to be the first field, to ensure correct drop order. Dropping @@ -21,9 +31,6 @@ pub struct Pty { backend: Backend, conout: ReadPipe, conin: WritePipe, - read_token: mio::Token, - write_token: mio::Token, - child_event_token: mio::Token, child_watcher: ChildExitWatcher, } @@ -39,51 +46,29 @@ impl Pty { conin: impl Into, child_watcher: ChildExitWatcher, ) -> Self { - Self { - backend: backend.into(), - conout: conout.into(), - conin: conin.into(), - read_token: 0.into(), - write_token: 0.into(), - child_event_token: 0.into(), - child_watcher, - } + Self { backend: backend.into(), conout: conout.into(), conin: conin.into(), child_watcher } } } +fn with_key(mut event: Event, key: usize) -> Event { + event.key = key; + event +} + impl EventedReadWrite for Pty { type Reader = ReadPipe; type Writer = WritePipe; #[inline] - fn register( + unsafe fn register( &mut self, - poll: &mio::Poll, - token: &mut dyn Iterator, - interest: mio::Ready, - poll_opts: mio::PollOpt, + poll: &Arc, + interest: polling::Event, + poll_opts: polling::PollMode, ) -> io::Result<()> { - self.read_token = token.next().unwrap(); - self.write_token = token.next().unwrap(); - - if interest.is_readable() { - poll.register(&self.conout, self.read_token, mio::Ready::readable(), poll_opts)? - } else { - poll.register(&self.conout, self.read_token, mio::Ready::empty(), poll_opts)? - } - if interest.is_writable() { - poll.register(&self.conin, self.write_token, mio::Ready::writable(), poll_opts)? - } else { - poll.register(&self.conin, self.write_token, mio::Ready::empty(), poll_opts)? - } - - self.child_event_token = token.next().unwrap(); - poll.register( - self.child_watcher.event_rx(), - self.child_event_token, - mio::Ready::readable(), - poll_opts, - )?; + self.conin.register(poll, with_key(interest, PTY_READ_WRITE_TOKEN), poll_opts); + self.conout.register(poll, with_key(interest, PTY_READ_WRITE_TOKEN), poll_opts); + self.child_watcher.register(poll, with_key(interest, PTY_CHILD_EVENT_TOKEN)); Ok(()) } @@ -91,36 +76,23 @@ impl EventedReadWrite for Pty { #[inline] fn reregister( &mut self, - poll: &mio::Poll, - interest: mio::Ready, - poll_opts: mio::PollOpt, + poll: &Arc, + interest: polling::Event, + poll_opts: polling::PollMode, ) -> io::Result<()> { - if interest.is_readable() { - poll.reregister(&self.conout, self.read_token, mio::Ready::readable(), poll_opts)?; - } else { - poll.reregister(&self.conout, self.read_token, mio::Ready::empty(), poll_opts)?; - } - if interest.is_writable() { - poll.reregister(&self.conin, self.write_token, mio::Ready::writable(), poll_opts)?; - } else { - poll.reregister(&self.conin, self.write_token, mio::Ready::empty(), poll_opts)?; - } - - poll.reregister( - self.child_watcher.event_rx(), - self.child_event_token, - mio::Ready::readable(), - poll_opts, - )?; + self.conin.register(poll, with_key(interest, PTY_READ_WRITE_TOKEN), poll_opts); + self.conout.register(poll, with_key(interest, PTY_READ_WRITE_TOKEN), poll_opts); + self.child_watcher.register(poll, with_key(interest, PTY_CHILD_EVENT_TOKEN)); Ok(()) } #[inline] - fn deregister(&mut self, poll: &mio::Poll) -> io::Result<()> { - poll.deregister(&self.conout)?; - poll.deregister(&self.conin)?; - poll.deregister(self.child_watcher.event_rx())?; + fn deregister(&mut self, _poll: &Arc) -> io::Result<()> { + self.conin.deregister(); + self.conout.deregister(); + self.child_watcher.deregister(); + Ok(()) } @@ -129,27 +101,13 @@ impl EventedReadWrite for Pty { &mut self.conout } - #[inline] - fn read_token(&self) -> mio::Token { - self.read_token - } - #[inline] fn writer(&mut self) -> &mut Self::Writer { &mut self.conin } - - #[inline] - fn write_token(&self) -> mio::Token { - self.write_token - } } impl EventedPty for Pty { - fn child_event_token(&self) -> mio::Token { - self.child_event_token - } - fn next_child_event(&mut self) -> Option { match self.child_watcher.event_rx().try_recv() { Ok(ev) => Some(ev), -- cgit