chiark / gitweb /
make route_packet async
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 17 Aug 2021 00:22:42 +0000 (01:22 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 17 Aug 2021 00:22:42 +0000 (01:22 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/client.rs
src/bin/server.rs
src/slip.rs

index cfb632e8ce359ed2d89d643854e52aa2c0258fe2..8597cfd3ba2264ccff8b81dfafe149e7f5286e80 100644 (file)
@@ -283,10 +283,10 @@ async fn run_client<C:HCC>(
               if addr != ic.link.client.0 { throw!(PE::Dst(addr)) }
               Ok(())
             },
-            |(o,())| Ok({ rx_queue.push(o); }),
+            |(o,())| future::ready(Ok({ rx_queue.push(o); })),
             |e| Ok::<_,SlipFramesError<Void>>( {
               error!("{} #{}: rx discarding: {}", &ic, req_num, e);
-            }))
+            })).await
             {
               Ok(()) => reporter.lock().success(),
               Err(SlipFramesError::ErrorOnlyBad) => {
index a45bec6d92e4351bd75f3484332925527e1302d1..57f9bc75caa6b813365234c4f9c8e79f85a53c80 100644 (file)
@@ -57,9 +57,9 @@ struct WebResponse {
 type WebResponseData = Vec<u8>;
 
 #[throws(PacketError)]
-pub fn route_packet(global: &Global,
-                    conn: &str, link: &dyn Display,
-                    packet: RoutedPacket, daddr: IpAddr)
+pub async fn route_packet(global: &Global,
+                          conn: &str, link: &(dyn Display + Sync),
+                          packet: RoutedPacket, daddr: IpAddr)
 {
   let c = &global.config;
   let trace = |how| trace!("{} {} route {} daddr={:?} len={}",
@@ -401,7 +401,7 @@ async fn run_client(global: Arc<Global>,
               &global, &conn, &ic.link.client, daddr,packet
             ),
               |e| Ok::<_,SlipFramesError<_>>({ warnings.add(&e)?; })
-            )?;
+            ).await?;
           }
 
           let oi = OutstandingInner {
index 6bb508bf2cfe25894aa00dcc3f27c5dfcaa4472d..f5980cc3b72f5d559f8170fc7bd50cce503ea57a 100644 (file)
@@ -31,30 +31,31 @@ pub enum SlipFramesError<E> where E: std::error::Error + 'static {
 }
   
 #[throws(SlipFramesError<EHE>)]
-pub fn checkn<AC, EH, EHE, OUT, ACR, M: SlipMime+Copy>(
+pub async fn checkn<AC, EH, EHE, OUT, FOUT, ACR, M: SlipMime+Copy>(
   mime: M,
   mtu: u32,
   data: &[u8],
   addr_chk: AC,
   mut out: OUT,
   mut error_handler: EH
-) where AC: Fn(&[u8]) -> Result<ACR, PacketError> + Copy,
-        OUT: FnMut((Box<[u8]>, ACR)) -> Result<(), PacketError>,
-        EH: FnMut(PacketError) -> Result<(), SlipFramesError<EHE>>,
-        EHE: std::error::Error + 'static,
+) where AC: Fn(&[u8]) -> Result<ACR, PacketError> + Copy + Send,
+        OUT: FnMut((Box<[u8]>, ACR)) -> FOUT + Send,
+        FOUT: Future<Output=Result<(), PacketError>> + Send,
+        EH: FnMut(PacketError) -> Result<(), SlipFramesError<EHE>> + Send,
+        EHE: std::error::Error + Send + 'static,
 {
   //  eprintln!("before: {:?}", DumpHex(data));
   if data.is_empty() { return }
   let mut ok = false;
   let mut err = false;
   for packet in data.split(|&c| c == SLIP_END) {
-    match (||{
+    match async {
       let checked = check1(mime, mtu, packet, addr_chk);
       if matches!(checked, Err(PacketError::Empty)) { return Ok::<_,PE>(()) }
-      out(checked?)?;
+      out(checked?).await?;
       ok = true;
       Ok::<_,PE>(())
-    })() {
+    }.await {
       Ok(()) => { },
       Err(e) => { err=true; error_handler(e)?; },
     }