From 718e8618544c4cdde78138655305eee7c08058ee Mon Sep 17 00:00:00 2001 From: Lizzy Fleckenstein Date: Sat, 18 Feb 2023 03:03:40 +0100 Subject: Don't spawn tasks --- src/send.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/send.rs') 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>>; -impl RudpSender { +pub struct RudpSender { + pub(crate) share: Arc>, +} + +// derive(Clone) adds unwanted Clone trait bound to P parameter +impl Clone for RudpSender

{ + fn clone(&self) -> Self { + Self { + share: Arc::clone(&self.share), + } + } +} + +impl RudpSender

{ pub async fn send(&self, pkt: Pkt<'_>) -> AckResult { self.share.send(PktType::Orig, pkt).await // TODO: splits } } -impl RudpShare { +impl RudpShare

{ 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::(PROTO_ID)?; -- cgit v1.2.3