diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-12-28 03:33:52 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-12-28 05:28:28 -0500 |
commit | f8780ca1e76286688b74d8a6c64d5fadf3cfd2a1 (patch) | |
tree | b1e0fe6a378f3a8810e0332ca572a86185fd556c /src/pty/async_io.rs | |
parent | b181b63a69d5db78769c1c3723a9940f66491466 (diff) | |
download | pty-process-f8780ca1e76286688b74d8a6c64d5fadf3cfd2a1.tar.gz pty-process-f8780ca1e76286688b74d8a6c64d5fadf3cfd2a1.zip |
wip
Diffstat (limited to 'src/pty/async_io.rs')
-rw-r--r-- | src/pty/async_io.rs | 49 |
1 files changed, 3 insertions, 46 deletions
diff --git a/src/pty/async_io.rs b/src/pty/async_io.rs index 304f403..d76c92c 100644 --- a/src/pty/async_io.rs +++ b/src/pty/async_io.rs @@ -1,48 +1,5 @@ -use std::os::unix::io::{AsRawFd as _, FromRawFd as _}; - -pub struct Pty { - 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() -> crate::error::Result<Self> { - let (pt_fd, ptsname) = super::create_pt()?; - - // safe because posix_openpt (or the previous functions operating on - // the result) would have returned an Err (causing us to return early) - // if the file descriptor was invalid. additionally, into_raw_fd gives - // up ownership over the file descriptor, allowing the newly created - // 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(crate::error::create_pty)?; - - Ok(Self { pt, ptsname }) - } - - fn pt(&self) -> &Self::Pt { - &self.pt - } - - fn pt_mut(&mut self) -> &mut Self::Pt { - &mut self.pt - } - - fn pts(&self) -> crate::error::Result<std::fs::File> { - let fh = std::fs::OpenOptions::new() - .read(true) - .write(true) - .open(&self.ptsname) - .map_err(crate::error::create_pty)?; - Ok(fh) - } - - fn resize(&self, size: &super::Size) -> crate::error::Result<()> { - super::set_term_size(self.pt().as_raw_fd(), size) - .map_err(crate::error::set_term_size) +impl super::Impl for async_io::Async<std::fs::File> { + fn new_from_fh(fh: std::fs::File) -> crate::Result<Self> { + Self::new(fh).map_err(crate::error::create_pty) } } |