aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorLizzy Fleckenstein <eliasfleckenstein@web.de>2022-12-28 23:30:02 +0100
committerLizzy Fleckenstein <eliasfleckenstein@web.de>2022-12-28 23:30:02 +0100
commitf160c0fa78744b337f03b619e2d8b61ed916402b (patch)
tree92367a3bffd313fa754cc104b2f98c0f91a4abc4 /src/main.rs
parent976be3aa3b50ef7721fce2d38ed5855ed64a719a (diff)
downloadmt_rudp-f160c0fa78744b337f03b619e2d8b61ed916402b.tar.xz
fix async
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index 241d324..a190bcd 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,11 +1,11 @@
#![feature(yeet_expr)]
#![feature(cursor_remaining)]
#![feature(hash_drain_filter)]
-#![feature(async_fn_in_trait)]
mod client;
pub mod error;
mod recv_worker;
+use async_trait::async_trait;
use byteorder::{BigEndian, WriteBytesExt};
pub use client::{connect, Sender as Client};
use num_enum::TryFromPrimitive;
@@ -24,10 +24,12 @@ pub const REL_BUFFER: usize = 0x8000;
pub const INIT_SEQNUM: u16 = 65500;
pub const TIMEOUT: u64 = 30;
+#[async_trait]
pub trait UdpSender: Send + Sync + 'static {
async fn send(&self, data: Vec<u8>) -> io::Result<()>;
}
+#[async_trait]
pub trait UdpReceiver: Send + Sync + 'static {
async fn recv(&self) -> io::Result<Vec<u8>>;
}
@@ -118,6 +120,12 @@ impl<S: UdpSender> ops::Deref for RudpReceiver<S> {
}
}
+impl<S: UdpSender> ops::DerefMut for RudpReceiver<S> {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ &mut self.pkt_rx
+ }
+}
+
pub fn new<S: UdpSender, R: UdpReceiver>(
id: u16,
remote_id: u16,
@@ -134,7 +142,10 @@ pub fn new<S: UdpSender, R: UdpReceiver>(
});
let recv_share = Arc::clone(&share);
- tokio::spawn(async { recv_worker::RecvWorker::new(udp_rx, recv_share, pkt_tx).await });
+ tokio::spawn(async {
+ let worker = recv_worker::RecvWorker::new(udp_rx, recv_share, pkt_tx);
+ worker.run().await;
+ });
(
RudpSender {
@@ -149,7 +160,7 @@ pub fn new<S: UdpSender, R: UdpReceiver>(
#[tokio::main]
async fn main() -> io::Result<()> {
//println!("{}", x.deep_size_of());
- let (tx, rx) = connect("127.0.0.1:30000").await?;
+ let (tx, mut rx) = connect("127.0.0.1:30000").await?;
let mut mtpkt = vec![];
mtpkt.write_u16::<BigEndian>(2)?; // high level type