From 7df6ab214908817073a346bcf06d776cfbe31bde Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sun, 7 Jun 2020 21:30:33 +0800 Subject: [PATCH] rpc: use async-recursion --- src/Cargo.lock | 12 ++++++++++++ src/runtime/Cargo.toml | 1 + src/runtime/src/rpc.rs | 17 ++++++++++------- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/Cargo.lock b/src/Cargo.lock index 58e773f..8a96b87 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -1,5 +1,16 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "async-recursion" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5444eec77a9ec2bfe4524139e09195862e981400c4358d3b760cae634e4c4ee" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "autocfg" version = "1.0.0" @@ -337,6 +348,7 @@ checksum = "bd7a31eed1591dcbc95d92ad7161908e72f4677f8fabf2a32ca49b4237cbf211" name = "runtime" version = "0.1.0" dependencies = [ + "async-recursion", "byteorder", "core_io", "cslice", diff --git a/src/runtime/Cargo.toml b/src/runtime/Cargo.toml index 1cd6c66..624fc16 100644 --- a/src/runtime/Cargo.toml +++ b/src/runtime/Cargo.toml @@ -18,6 +18,7 @@ core_io = { version = "0.1", features = ["alloc", "collections"] } byteorder = { version = "1.3", default-features = false } void = { version = "1", default-features = false } futures = { version = "0.3", default-features = false, features = ["async-await"] } +async-recursion = "0.3" libboard_zynq = { git = "https://git.m-labs.hk/M-Labs/zc706.git" } libsupport_zynq = { git = "https://git.m-labs.hk/M-Labs/zc706.git" } libcortex_a9 = { git = "https://git.m-labs.hk/M-Labs/zc706.git" } diff --git a/src/runtime/src/rpc.rs b/src/runtime/src/rpc.rs index fbaa209..ff7aa86 100644 --- a/src/runtime/src/rpc.rs +++ b/src/runtime/src/rpc.rs @@ -2,15 +2,18 @@ use core::str; use cslice::{CSlice, CMutSlice}; use log::debug; +use core_io::{Write, Error}; use libboard_zynq::smoltcp; use libasync::smoltcp::TcpStream; -use core_io::{Write, Error}; +use alloc::boxed::Box; +use async_recursion::async_recursion; use crate::proto_core_io::ProtoWrite; use crate::proto_async; use self::tag::{Tag, TagIterator, split_tag}; -async unsafe fn recv_value(stream: &TcpStream, tag: Tag<'_>, data: &mut *mut (), +#[async_recursion(?Send)] +async unsafe fn recv_value(stream: &TcpStream, tag: Tag<'async_recursion>, data: &mut *mut (), alloc: &dyn Fn(usize) -> *mut ()) -> Result<(), smoltcp::Error> { @@ -51,7 +54,7 @@ async unsafe fn recv_value(stream: &TcpStream, tag: Tag<'_>, data: &mut *mut (), let mut it = it.clone(); for _ in 0..arity { let tag = it.next().expect("truncated tag"); - //TODO: recv_value(reader, tag, data, alloc)? + recv_value(stream, tag, data, alloc).await?; } Ok(()) } @@ -65,16 +68,16 @@ async unsafe fn recv_value(stream: &TcpStream, tag: Tag<'_>, data: &mut *mut (), let mut data = (*ptr).elements; for _ in 0..(*ptr).length as usize { - //TODO: recv_value(reader, tag, &mut data, alloc).await? + recv_value(stream, tag, &mut data, alloc).await? } Ok(()) }) } Tag::Range(it) => { let tag = it.clone().next().expect("truncated tag"); - /*TODO: recv_value(reader, tag, data, alloc).await?; - recv_value(reader, tag, data, alloc).await?; - recv_value(reader, tag, data, alloc).await?;*/ + recv_value(stream, tag, data, alloc).await?; + recv_value(stream, tag, data, alloc).await?; + recv_value(stream, tag, data, alloc).await?; Ok(()) } Tag::Keyword(_) => unreachable!(),