Skip to content

Commit

Permalink
feat: Fix tokio
Browse files Browse the repository at this point in the history
  • Loading branch information
john-bv committed Jan 14, 2023
1 parent c5ff04a commit 27a2139
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rakrs"
version = "0.3.0-rc.3"
version = "0.3.0-rc.4"
authors = ["Bavfalcon9 <olybear9@gmail.com>"]
edition = "2021"

Expand Down
16 changes: 14 additions & 2 deletions src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ use tokio::{
task::{self, JoinHandle},
time::sleep,
};
#[cfg(feature = "async_tokio")]
pub enum RecvError {
Closed,
Timeout,
}

use crate::{
protocol::{
Expand Down Expand Up @@ -234,7 +239,7 @@ impl Connection {
///
pub async fn init_net_recv(
&self,
net: Receiver<Vec<u8>>,
mut net: Receiver<Vec<u8>>,
sender: Sender<Vec<u8>>,
) -> task::JoinHandle<()> {
let recv_time = self.recv_time.clone();
Expand Down Expand Up @@ -471,10 +476,17 @@ impl Connection {

/// Recieve a packet from the client.
pub async fn recv(&mut self) -> Result<Vec<u8>, RecvError> {
let q = self.internal_net_recv.as_ref().lock().await;
#[allow(unused_mut)]
let mut q = self.internal_net_recv.as_ref().lock().await;
match q.recv().await {
#[cfg(feature = "async_std")]
Ok(packet) => Ok(packet),
#[cfg(feature = "async_std")]
Err(e) => Err(e),
#[cfg(feature = "async_tokio")]
Some(packet) => Ok(packet),
#[cfg(feature = "async_tokio")]
None => Err(RecvError::Closed),
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/connection/queue/recv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub struct RecvQueue {
/// (seq, time)
ack: HashSet<(u32, u64)>,
nack: HashSet<u32>,
highest_seq: u32,
ready: Vec<Vec<u8>>,
}

Expand All @@ -37,7 +36,6 @@ impl RecvQueue {
nack: HashSet::new(),
window: ReliableWindow::new(),
reliable_window: ReliableWindow::new(),
highest_seq: 0,
ready: Vec::new(),
order_channels: HashMap::new(),
}
Expand Down

0 comments on commit 27a2139

Please sign in to comment.