Skip to content

Commit

Permalink
Improve stdio tunnel on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
erebe committed May 25, 2024
1 parent 8502b2c commit 7a99905
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ pub mod server {
use log::error;
use scopeguard::guard;
use std::io::{Read, Write};
use std::sync::mpsc;
use std::sync::{Arc, mpsc};

Check warning on line 38 in src/stdio.rs

View workflow job for this annotation

GitHub Actions / Build - Windows x86_64

unused import: `mpsc`

Check warning on line 38 in src/stdio.rs

View workflow job for this annotation

GitHub Actions / Build - Windows x86

unused import: `mpsc`
use std::{io, process, thread};

Check warning on line 39 in src/stdio.rs

View workflow job for this annotation

GitHub Actions / Build - Windows x86_64

unused import: `process`

Check warning on line 39 in src/stdio.rs

View workflow job for this annotation

GitHub Actions / Build - Windows x86

unused import: `process`
use parking_lot::Mutex;
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite};
use tokio::sync::oneshot;
use tokio::task::LocalSet;
Expand All @@ -51,11 +52,13 @@ pub mod server {

let stdin = io::stdin();
let (send, recv) = tokio::sync::mpsc::unbounded_channel();
let (abort_tx, mut abort_rx) = oneshot::channel::<()>();
let (abort_tx, abort_rx) = oneshot::channel::<()>();
let abort_rx = Arc::new(Mutex::new(abort_rx));
let abort_rx2 = abort_rx.clone();
thread::spawn(move || {
let _restore_terminal = guard((), move |_| {
let _ = crossterm::terminal::disable_raw_mode();
abort_rx.close();
abort_rx.lock().close();
});
let stdin = stdin;
let mut stdin = stdin.lock();
Expand All @@ -81,6 +84,7 @@ pub mod server {
let task = async move {
let _restore_terminal = guard((), move |_| {
let _ = crossterm::terminal::disable_raw_mode();
abort_rx2.lock().close();
});
let mut stdout = io::stdout().lock();
let mut buf = [0u8; 65536];
Expand Down

0 comments on commit 7a99905

Please sign in to comment.