diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-02-23 01:22:49 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-02-23 01:52:03 -0500 |
commit | e6a3feb286ed68876a7c9fd9162266f741ca1a32 (patch) | |
tree | 5e1dfd36fe147190320cde9e49a1755e8446e543 /src/pty/async_io.rs | |
parent | f3e8046eff473aa9bf940b7fbd156cf3dfbfa352 (diff) | |
download | pty-process-e6a3feb286ed68876a7c9fd9162266f741ca1a32.tar.gz pty-process-e6a3feb286ed68876a7c9fd9162266f741ca1a32.zip |
add async implementations of the pty itself
Diffstat (limited to 'src/pty/async_io.rs')
-rw-r--r-- | src/pty/async_io.rs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/pty/async_io.rs b/src/pty/async_io.rs index 84097f9..3021f7a 100644 --- a/src/pty/async_io.rs +++ b/src/pty/async_io.rs @@ -1,13 +1,15 @@ use crate::error::*; -use std::os::unix::io::FromRawFd as _; +use std::os::unix::io::{AsRawFd as _, FromRawFd as _}; pub struct Pty { - pt: std::fs::File, + pt: async_io::Async<std::fs::File>, ptsname: std::path::PathBuf, } impl super::Pty for Pty { + type Pt = async_io::Async<std::fs::File>; + fn new() -> Result<Self> { let (pt_fd, ptsname) = super::create_pt()?; @@ -18,10 +20,12 @@ impl super::Pty for Pty { // File object to take full ownership. let pt = unsafe { std::fs::File::from_raw_fd(pt_fd) }; + let pt = async_io::Async::new(pt).map_err(|e| Error::AsyncPty(e))?; + Ok(Self { pt, ptsname }) } - fn pt(&self) -> &std::fs::File { + fn pt(&self) -> &Self::Pt { &self.pt } @@ -33,4 +37,9 @@ impl super::Pty for Pty { .map_err(|e| Error::OpenPts(self.ptsname.clone(), e))?; Ok(fh) } + + fn resize(&self, size: &super::Size) -> Result<()> { + super::set_term_size(self.pt().as_raw_fd(), size) + .map_err(Error::SetTermSize) + } } |