From e6a3feb286ed68876a7c9fd9162266f741ca1a32 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 23 Feb 2021 01:22:49 -0500 Subject: add async implementations of the pty itself --- src/pty/tokio.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/pty/tokio.rs') diff --git a/src/pty/tokio.rs b/src/pty/tokio.rs index 84097f9..995a154 100644 --- a/src/pty/tokio.rs +++ b/src/pty/tokio.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: tokio::fs::File, ptsname: std::path::PathBuf, } impl super::Pty for Pty { + type Pt = tokio::fs::File; + fn new() -> Result { 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 = tokio::fs::File::from_std(pt); + 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) + } } -- cgit v1.2.3-54-g00ecf