diff options
author | Lizzy Fleckenstein <eliasfleckenstein@web.de> | 2023-02-18 03:03:40 +0100 |
---|---|---|
committer | Lizzy Fleckenstein <eliasfleckenstein@web.de> | 2023-02-18 03:05:06 +0100 |
commit | 718e8618544c4cdde78138655305eee7c08058ee (patch) | |
tree | bb578698c985ebf8c9601f325d1fc90dc0153e46 /src/send.rs | |
parent | 88ff69e7a8e90a4fa3929fa173ed93e99b60f37c (diff) | |
download | mt_rudp-718e8618544c4cdde78138655305eee7c08058ee.tar.xz |
Don't spawn tasks
Diffstat (limited to 'src/send.rs')
-rw-r--r-- | src/send.rs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/send.rs b/src/send.rs index a3a7f03..2c449e1 100644 --- a/src/send.rs +++ b/src/send.rs @@ -1,17 +1,33 @@ use super::*; use byteorder::{BigEndian, WriteBytesExt}; -use std::io::{self, Write}; +use std::{ + io::{self, Write}, + sync::Arc, +}; use tokio::sync::watch; pub type AckResult = io::Result<Option<watch::Receiver<bool>>>; -impl<S: UdpSender> RudpSender<S> { +pub struct RudpSender<P: UdpPeer> { + pub(crate) share: Arc<RudpShare<P>>, +} + +// derive(Clone) adds unwanted Clone trait bound to P parameter +impl<P: UdpPeer> Clone for RudpSender<P> { + fn clone(&self) -> Self { + Self { + share: Arc::clone(&self.share), + } + } +} + +impl<P: UdpPeer> RudpSender<P> { pub async fn send(&self, pkt: Pkt<'_>) -> AckResult { self.share.send(PktType::Orig, pkt).await // TODO: splits } } -impl<S: UdpSender> RudpShare<S> { +impl<P: UdpPeer> RudpShare<P> { pub async fn send(&self, tp: PktType, pkt: Pkt<'_>) -> AckResult { let mut buf = Vec::with_capacity(4 + 2 + 1 + 1 + 2 + 1 + pkt.data.len()); buf.write_u32::<BigEndian>(PROTO_ID)?; |