Read data from PTY. Blocks until data is available, PTY closes, or an error occurs. Returns Ok(Some(bytes)) for data, Ok(None) for clean close, Err for errors.
(&self)
| 2477 | /// Blocks until data is available, PTY closes, or an error occurs. |
| 2478 | /// Returns Ok(Some(bytes)) for data, Ok(None) for clean close, Err for errors. |
| 2479 | pub async fn read(&self) -> anyhow::Result<Option<Vec<u8>>> { |
| 2480 | let mut channel = self.channel.lock().await; |
| 2481 | loop { |
| 2482 | match channel.wait().await { |
| 2483 | Some(russh::ChannelMsg::Data { data }) => return Ok(Some(data.to_vec())), |
| 2484 | Some(russh::ChannelMsg::ExtendedData { data, .. }) => { |
| 2485 | return Ok(Some(data.to_vec())); |
| 2486 | } |
| 2487 | Some(russh::ChannelMsg::Eof) | Some(russh::ChannelMsg::Close) => return Ok(None), |
| 2488 | Some(russh::ChannelMsg::ExitStatus { .. }) => return Ok(None), |
| 2489 | Some(_) => { |
| 2490 | // WindowAdjust, Success, RequestSuccess, etc. — skip and keep reading |
| 2491 | continue; |
| 2492 | } |
| 2493 | None => return Ok(None), |
| 2494 | } |
| 2495 | } |
| 2496 | } |
| 2497 | |
| 2498 | /// Close PTY session |
| 2499 | pub async fn close(self) -> anyhow::Result<()> { |