From e28b277980763b88d2828812bff2c0b9546d3d25 Mon Sep 17 00:00:00 2001 From: iximeow Date: Thu, 29 Dec 2022 09:19:07 +0000 Subject: do not use buggy AsyncWrite impl for file transfer, spawn_blocking a blocking task --- src/ci_runner.rs | 41 +++-------------------------------------- 1 file changed, 3 insertions(+), 38 deletions(-) (limited to 'src/ci_runner.rs') diff --git a/src/ci_runner.rs b/src/ci_runner.rs index 3c0104f..a47d298 100644 --- a/src/ci_runner.rs +++ b/src/ci_runner.rs @@ -16,6 +16,8 @@ use std::marker::Unpin; mod lua; mod io; +use crate::io::ArtifactStream; + #[derive(Debug)] enum WorkAcquireError { Reqwest(reqwest::Error), @@ -100,9 +102,7 @@ impl RunningJob { if resp.status() == StatusCode::OK { eprintln!("[+] artifact '{}' started", name); - Ok(ArtifactStream { - sender, - }) + Ok(ArtifactStream::new(sender)) } else { Err(format!("[-] unable to create artifact: {:?}", resp)) } @@ -319,41 +319,6 @@ impl RunningJob { } } -struct ArtifactStream { - sender: hyper::body::Sender, -} - -impl tokio::io::AsyncWrite for ArtifactStream { - fn poll_write( - self: Pin<&mut Self>, - cx: &mut Context, - buf: &[u8] - ) -> Poll> { - match self.get_mut().sender.try_send_data(buf.to_vec().into()) { - Ok(()) => { - Poll::Ready(Ok(buf.len())) - }, - _ => { - Poll::Pending - } - } - } - - fn poll_flush( - self: Pin<&mut Self>, - _cx: &mut Context - ) -> Poll> { - Poll::Ready(Ok(())) - } - - fn poll_shutdown( - self: Pin<&mut Self>, - _cx: &mut Context - ) -> Poll> { - Poll::Ready(Ok(())) - } -} - impl RunnerClient { async fn new(host: &str, mut sender: hyper::body::Sender, mut res: Response) -> Result { if res.status() != StatusCode::OK { -- cgit v1.1