|
|
@ -62,10 +62,11 @@ impl Client {
|
|
|
|
pub fn streams(
|
|
|
|
pub fn streams(
|
|
|
|
rx: Box<dyn AsyncBufRead + Unpin + Send>,
|
|
|
|
rx: Box<dyn AsyncBufRead + Unpin + Send>,
|
|
|
|
tx: Box<dyn AsyncWrite + Unpin + Send>,
|
|
|
|
tx: Box<dyn AsyncWrite + Unpin + Send>,
|
|
|
|
|
|
|
|
err: Option<Box<dyn AsyncBufRead + Unpin + Send>>,
|
|
|
|
id: usize,
|
|
|
|
id: usize,
|
|
|
|
process: Option<Child>,
|
|
|
|
process: Option<Child>,
|
|
|
|
) -> Result<(Self, UnboundedReceiver<Payload>)> {
|
|
|
|
) -> Result<(Self, UnboundedReceiver<Payload>)> {
|
|
|
|
let (server_rx, server_tx) = Transport::start(rx, tx, id);
|
|
|
|
let (server_rx, server_tx) = Transport::start(rx, tx, err, id);
|
|
|
|
let (client_rx, client_tx) = unbounded_channel();
|
|
|
|
let (client_rx, client_tx) = unbounded_channel();
|
|
|
|
|
|
|
|
|
|
|
|
let client = Self {
|
|
|
|
let client = Self {
|
|
|
@ -92,7 +93,7 @@ impl Client {
|
|
|
|
) -> Result<(Self, UnboundedReceiver<Payload>)> {
|
|
|
|
) -> Result<(Self, UnboundedReceiver<Payload>)> {
|
|
|
|
let stream = TcpStream::connect(addr).await?;
|
|
|
|
let stream = TcpStream::connect(addr).await?;
|
|
|
|
let (rx, tx) = stream.into_split();
|
|
|
|
let (rx, tx) = stream.into_split();
|
|
|
|
Self::streams(Box::new(BufReader::new(rx)), Box::new(tx), id, None)
|
|
|
|
Self::streams(Box::new(BufReader::new(rx)), Box::new(tx), None, id, None)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn stdio(
|
|
|
|
pub fn stdio(
|
|
|
@ -113,10 +114,12 @@ impl Client {
|
|
|
|
// TODO: do we need bufreader/writer here? or do we use async wrappers on unblock?
|
|
|
|
// TODO: do we need bufreader/writer here? or do we use async wrappers on unblock?
|
|
|
|
let writer = BufWriter::new(process.stdin.take().expect("Failed to open stdin"));
|
|
|
|
let writer = BufWriter::new(process.stdin.take().expect("Failed to open stdin"));
|
|
|
|
let reader = BufReader::new(process.stdout.take().expect("Failed to open stdout"));
|
|
|
|
let reader = BufReader::new(process.stdout.take().expect("Failed to open stdout"));
|
|
|
|
|
|
|
|
let errors = BufReader::new(process.stderr.take().expect("Failed to open stderr"));
|
|
|
|
|
|
|
|
|
|
|
|
Self::streams(
|
|
|
|
Self::streams(
|
|
|
|
Box::new(BufReader::new(reader)),
|
|
|
|
Box::new(BufReader::new(reader)),
|
|
|
|
Box::new(writer),
|
|
|
|
Box::new(writer),
|
|
|
|
|
|
|
|
Some(Box::new(BufReader::new(errors))),
|
|
|
|
id,
|
|
|
|
id,
|
|
|
|
Some(process),
|
|
|
|
Some(process),
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -167,6 +170,7 @@ impl Client {
|
|
|
|
Self::streams(
|
|
|
|
Self::streams(
|
|
|
|
Box::new(BufReader::new(rx)),
|
|
|
|
Box::new(BufReader::new(rx)),
|
|
|
|
Box::new(tx),
|
|
|
|
Box::new(tx),
|
|
|
|
|
|
|
|
None,
|
|
|
|
id,
|
|
|
|
id,
|
|
|
|
Some(process),
|
|
|
|
Some(process),
|
|
|
|
)
|
|
|
|
)
|
|
|
|