@@ -7,7 +7,8 @@ use serde_json::{from_value, to_value, Value};
7use std::process::Stdio;
7use std::process::Stdio;
8use std::sync::atomic::{AtomicU64, Ordering};
8use std::sync::atomic::{AtomicU64, Ordering};
9use tokio::{
9use tokio::{
10− io::{BufReader, BufWriter},
10+ io::{AsyncBufRead, AsyncWrite, BufReader, BufWriter},
11 process::{Child, Command},
12 process::{Child, Command},
12 sync::mpsc::{channel, UnboundedReceiver, UnboundedSender},
13 sync::mpsc::{channel, UnboundedReceiver, UnboundedSender},
@@ -257,7 +258,7 @@ struct VariablesResponseBody {
257#[derive(Debug)]
258#[derive(Debug)]
258pub struct Client {
259pub struct Client {
259 id: usize,
260 id: usize,
260− _process: Child,
261+ _process: Option<Child>,
261 server_tx: UnboundedSender<Request>,
262 server_tx: UnboundedSender<Request>,
262 server_rx: UnboundedReceiver<Payload>,
263 server_rx: UnboundedReceiver<Payload>,
263 request_counter: AtomicU64,
264 request_counter: AtomicU64,
@@ -265,7 +266,33 @@ pub struct Client {
267impl Client {
268impl Client {
270+ rx: Box<dyn AsyncBufRead + Unpin + Send>,
271+ tx: Box<dyn AsyncWrite + Unpin + Send>,
273+ process: Option<Child>,
275+ let (server_rx, server_tx) = Transport::start(rx, tx, id);
282+ request_counter: AtomicU64::new(0),
289+ pub async fn tcp(addr: std::net::SocketAddr, id: usize) -> Result<Self> {
290+ let stream = TcpStream::connect(addr).await?;
291+ let (rx, tx) = stream.into_split();
292+ Self::streams(Box::new(BufReader::new(rx)), Box::new(tx), id, None)
268− pub fn start(cmd: &str, args: Vec<&str>, id: usize) -> Result<Self> {
295+ pub fn stdio(cmd: &str, args: Vec<&str>, id: usize) -> Result<Self> {
269 let process = Command::new(cmd)
296 let process = Command::new(cmd)
270 .args(args)
297 .args(args)
271 .stdin(Stdio::piped())
298 .stdin(Stdio::piped())
@@ -280,18 +307,12 @@ impl Client {
280 let writer = BufWriter::new(process.stdin.take().expect("Failed to open stdin"));
307 let writer = BufWriter::new(process.stdin.take().expect("Failed to open stdin"));
281 let reader = BufReader::new(process.stdout.take().expect("Failed to open stdout"));
308 let reader = BufReader::new(process.stdout.take().expect("Failed to open stdout"));
283− let (server_rx, server_tx) = Transport::start(Box::new(reader), Box::new(writer), id);
310+ Self::streams(
284−
311+ Box::new(BufReader::new(reader)),
285− let client = Self {
312+ Box::new(writer),
287− _process: process,
314+ Some(process),
290− request_counter: AtomicU64::new(0),
297 pub fn id(&self) -> usize {
318 pub fn id(&self) -> usize {