From 98b4178e7bbdc256cf270763a59d3dc7c8d3f957 Mon Sep 17 00:00:00 2001 From: Lizzy Fleckenstein Date: Thu, 22 Dec 2022 23:26:09 +0100 Subject: fix --- src/main.rs | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index da53573..2a5ff2f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,9 +4,9 @@ mod client; pub mod error; mod recv_worker; -use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; +use byteorder::{BigEndian, WriteBytesExt}; pub use client::{connect, Sender as Client}; -use num_enum::{TryFromPrimitive, TryFromPrimitiveError}; +use num_enum::TryFromPrimitive; use std::{ io::{self, Write}, ops, @@ -20,8 +20,6 @@ pub const NUM_CHANS: usize = 3; pub const REL_BUFFER: usize = 0x8000; pub const INIT_SEQNUM: u16 = 65500; -pub type Error = error::Error; - pub trait UdpSender: Send + Sync + 'static { fn send(&self, data: Vec) -> io::Result<()>; } @@ -62,6 +60,7 @@ pub struct Pkt { data: T, } +pub type Error = error::Error; pub type InPkt = Result>, Error>; #[derive(Debug)] @@ -87,15 +86,6 @@ pub struct RudpSender { } impl RudpShare { - pub fn new(id: u16, remote_id: u16, udp_tx: S) -> Self { - Self { - id, - remote_id, - udp_tx, - chans: (0..NUM_CHANS).map(|_| AckChan).collect(), - } - } - pub fn send(&self, tp: PktType, pkt: Pkt<&[u8]>) -> io::Result<()> { let mut buf = Vec::with_capacity(4 + 2 + 1 + 1 + pkt.data.len()); buf.write_u32::(PROTO_ID)?; @@ -132,10 +122,15 @@ pub fn new( ) -> (RudpSender, RudpReceiver) { let (pkt_tx, pkt_rx) = mpsc::channel(); - let share = Arc::new(RudpShare::new(id, remote_id, udp_tx)); + let share = Arc::new(RudpShare { + id, + remote_id, + udp_tx, + chans: (0..NUM_CHANS).map(|_| AckChan).collect(), + }); let recv_share = Arc::clone(&share); - thread::spawn(move || { + thread::spawn(|| { recv_worker::RecvWorker::new(udp_rx, recv_share, pkt_tx).run(); }); -- cgit v1.2.3