Skip to content

Commit

Permalink
Dump Concr
Browse files Browse the repository at this point in the history
  • Loading branch information
Kris030 committed Jul 27, 2023
1 parent 0ba7d6e commit 7e67f6b
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 379 deletions.
73 changes: 2 additions & 71 deletions client/src/transports/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ impl Transport for Http {
C: Command,
C::Return: Send + 'static,
{
let concrete: cmd::Concrete = cmd.into();
let cmd = cmd::concrete::Concr::new(cmd.into());

let body = self.runtime.block_on(async {
let req = self
.client
.post(&self.base_url)
.send_body(concrete.to_string())
.send_body(cmd.to_string())
.await;

let mut res = match req {
Expand All @@ -50,72 +50,3 @@ impl Transport for Http {
Ok(roblib::text_format::de::from_str(&body)?)
}
}

// #[cfg(feature = "async")]
// pub struct HttpAsync {
// handle: futures::lock::Mutex<Option<tokio::task::JoinHandle<anyhow::Result<()>>>>,
// tx_cmd: futures::lock::Mutex<futures::channel::mpsc::UnboundedSender<cmd::Concrete>>,
// rx_res: futures::lock::Mutex<futures::channel::mpsc::UnboundedReceiver<String>>,
// }

// #[cfg(feature = "async")]
// impl HttpAsync {
// pub async fn new(base_url: &str) -> anyhow::Result<HttpAsync> {
// let url = format!("{base_url}/cmd");

// let (tx_cmd, rx_cmd) = futures::channel::mpsc::unbounded();
// let (tx_res, rx_res) = futures::channel::mpsc::unbounded();

// Ok(Self {
// handle: Some(actix_rt::spawn(Self::run(url, rx_cmd, tx_res))).into(),
// tx_cmd: tx_cmd.into(),
// rx_res: rx_res.into(),
// })
// }

// async fn run(
// url: String,
// mut rx_cmd: futures::channel::mpsc::UnboundedReceiver<cmd::Concrete>,
// mut tx_res: futures::channel::mpsc::UnboundedSender<String>,
// ) -> anyhow::Result<()> {
// use futures_util::{SinkExt, StreamExt};

// let client = Client::default();

// while let Some(cmd) = rx_cmd.next().await {
// let req = client.post(&url).send_body(cmd.to_string());
// let mut res = match req.await {
// Ok(r) => r,
// Err(e) => return Err(anyhow::Error::msg(e.to_string())),
// };

// let body = res.body().await?;
// let body = String::from_utf8(body.to_vec())?;

// tx_res.send(body).await?;
// }

// Ok(())
// }
// }

// #[cfg(feature = "async")]
// #[cfg_attr(feature = "async", async_trait::async_trait)]
// impl<'a> super::TransportAsync<'a> for HttpAsync {
// async fn cmd_async<C: Command<'a> + Send>(&self, cmd: C) -> anyhow::Result<C::Return> {
// use futures_util::{SinkExt, StreamExt};

// self.tx_cmd.lock().await.send(cmd.into()).await?;

// let Some(res) = self.rx_res.lock().await.next().await else {
// if let Some(r) = self.handle.lock().await.take() {
// r.await??;
// unreachable!("HTTP client terminated without error???")
// } else {
// return Err(anyhow::Error::msg("HTTP client already terminated"));
// }
// };

// Ok(roblib::text_format::de::from_str(&res)?)
// }
// }
4 changes: 2 additions & 2 deletions client/src/transports/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ impl Transport for Tcp {
C: roblib::cmd::Command,
C::Return: Send + 'static,
{
let concrete: cmd::Concrete = cmd.into();
let cmd = cmd::concrete::Concr::new(cmd.into());

let mut id_handle = self.id.lock().unwrap();
bincode::serialize_into(&self.socket, &(*id_handle, concrete))?;
bincode::serialize_into(&self.socket, &(*id_handle, cmd))?;

*id_handle += 1;

Expand Down
4 changes: 2 additions & 2 deletions client/src/transports/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ impl Transport for Udp {
let id = *id_handle;
*id_handle = id + 1;

let concrete: cmd::Concrete = cmd.into();
self.sock.send(&bincode::serialize(&(id, concrete))?)?;
let cmd = cmd::concrete::Concr::new(cmd.into());
self.sock.send(&bincode::serialize(&(id, cmd))?)?;

Ok(if has_return::<C>() {
let (tx, rx) = std::sync::mpsc::sync_channel(1);
Expand Down
Loading

1 comment on commit 7e67f6b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Artifacts

View all

base roland
aarch64-unknown-linux-gnu Download Download
armv7-unknown-linux-gnueabihf Download Download
x86_64-pc-windows-msvc Download Download
x86_64-unknown-linux-gnu Download Download

Please sign in to comment.