Skip to content

Commit

Permalink
Temporary fix #4
Browse files Browse the repository at this point in the history
  • Loading branch information
JellyBrick committed Apr 29, 2020
1 parent ba49a00 commit dae561b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ lto = true
dns-lookup = "1.0.2"
jni = "0.16.0"
tokio = { version = "0.2.19", features = ["udp"] }
lazy_static = "1.4.0"
lazy_static = "1.4.0"
linked-hash-map = "0.5.2"
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<'a> Manager<'a> {

fn get_target_time(&self, current_time: u128) -> u128 {
if let Ok(manager) = self.boxed_manager_mutex.try_lock() {
if let Some(item) = manager.queue_linked.front() {
if let Some((key, item)) = manager.queues.front() {
item.next_due_time
} else {
current_time + manager.packet_interval
Expand Down Expand Up @@ -173,7 +173,7 @@ impl<'a> Manager<'a> {

fn process_next(&self, mut current_time: u128) -> (Option<packet::Unsent>, u128) {
if let Ok(mut manager) = self.boxed_manager_mutex.try_lock() {
if let Some(mut item) = manager.queue_linked.pop_front() {
if let Some((key, mut item)) = manager.queues.pop_front() {
if item.next_due_time == 0 {
item.next_due_time = current_time;
} else if item.next_due_time - current_time >= 1500000 {
Expand All @@ -186,7 +186,7 @@ impl<'a> Manager<'a> {
} else {
item.next_due_time = manager.packet_interval;
}
manager.queue_linked.push_back(item);
manager.queues.insert(key, item);
(Some(packet), self.get_target_time(current_time))
} else {
(None, current_time + manager.packet_interval)
Expand Down
6 changes: 2 additions & 4 deletions src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,19 @@ pub struct Item<'a> {
}

pub struct Manager<'a> {
pub queues: std::collections::HashMap<u64, Item<'a>>,
pub queues: linked_hash_map::LinkedHashMap<u64, Item<'a>>,
pub queue_buffer_capacity: usize,
pub packet_interval: u128,
pub shutting_down: bool,
pub queue_linked: std::collections::LinkedList<Item<'a>>,
}

impl Manager<'_> {
pub fn new<'a>(queue_buffer_capacity: usize, packet_interval: u128) -> Manager<'a> {
Manager {
queues: Default::default(),
queues: linked_hash_map::LinkedHashMap::new(),
queue_buffer_capacity,
packet_interval,
shutting_down: false,
queue_linked: Default::default(),
}
}
}

0 comments on commit dae561b

Please sign in to comment.