|
|
@ -55,7 +55,7 @@ impl Transport {
|
|
|
|
server_stdin: Box<dyn AsyncWrite + Unpin + Send>,
|
|
|
|
server_stdin: Box<dyn AsyncWrite + Unpin + Send>,
|
|
|
|
server_stderr: Option<Box<dyn AsyncBufRead + Unpin + Send>>,
|
|
|
|
server_stderr: Option<Box<dyn AsyncBufRead + Unpin + Send>>,
|
|
|
|
id: usize,
|
|
|
|
id: usize,
|
|
|
|
) -> (UnboundedReceiver<Payload>, UnboundedSender<Request>) {
|
|
|
|
) -> (UnboundedReceiver<Payload>, UnboundedSender<Payload>) {
|
|
|
|
let (client_tx, rx) = unbounded_channel();
|
|
|
|
let (client_tx, rx) = unbounded_channel();
|
|
|
|
let (tx, client_rx) = unbounded_channel();
|
|
|
|
let (tx, client_rx) = unbounded_channel();
|
|
|
|
|
|
|
|
|
|
|
@ -140,14 +140,14 @@ impl Transport {
|
|
|
|
async fn send_payload_to_server(
|
|
|
|
async fn send_payload_to_server(
|
|
|
|
&self,
|
|
|
|
&self,
|
|
|
|
server_stdin: &mut Box<dyn AsyncWrite + Unpin + Send>,
|
|
|
|
server_stdin: &mut Box<dyn AsyncWrite + Unpin + Send>,
|
|
|
|
mut req: Request,
|
|
|
|
mut payload: Payload,
|
|
|
|
) -> Result<()> {
|
|
|
|
) -> Result<()> {
|
|
|
|
let back_ch = req.back_ch.take();
|
|
|
|
if let Payload::Request(request) = &mut payload {
|
|
|
|
let seq = req.seq;
|
|
|
|
if let Some(back) = request.back_ch.take() {
|
|
|
|
let json = serde_json::to_string(&Payload::Request(req))?;
|
|
|
|
self.pending_requests.lock().await.insert(request.seq, back);
|
|
|
|
if let Some(back) = back_ch {
|
|
|
|
}
|
|
|
|
self.pending_requests.lock().await.insert(seq, back);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let json = serde_json::to_string(&payload)?;
|
|
|
|
self.send_string_to_server(server_stdin, json).await
|
|
|
|
self.send_string_to_server(server_stdin, json).await
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -254,11 +254,11 @@ impl Transport {
|
|
|
|
async fn send(
|
|
|
|
async fn send(
|
|
|
|
transport: Arc<Self>,
|
|
|
|
transport: Arc<Self>,
|
|
|
|
mut server_stdin: Box<dyn AsyncWrite + Unpin + Send>,
|
|
|
|
mut server_stdin: Box<dyn AsyncWrite + Unpin + Send>,
|
|
|
|
mut client_rx: UnboundedReceiver<Request>,
|
|
|
|
mut client_rx: UnboundedReceiver<Payload>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
while let Some(req) = client_rx.recv().await {
|
|
|
|
while let Some(payload) = client_rx.recv().await {
|
|
|
|
transport
|
|
|
|
transport
|
|
|
|
.send_payload_to_server(&mut server_stdin, req)
|
|
|
|
.send_payload_to_server(&mut server_stdin, payload)
|
|
|
|
.await
|
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
}
|
|
|
|