aboutsummaryrefslogtreecommitdiff
path: root/p2p
diff options
context:
space:
mode:
authorhozan23 <hozan23@proton.me>2023-11-10 11:29:30 +0300
committerhozan23 <hozan23@proton.me>2023-11-10 11:29:30 +0300
commit24364ab8b4acf48f19d72c1b6d06c20478635eaf (patch)
tree039b3189654c1a3a7e545bce02f1b7c47d378a3e /p2p
parentd0fac4f4cdd26048ae84707d08ef03dde2a25ac3 (diff)
p2p: use VecDeque for connection queue
Diffstat (limited to 'p2p')
-rw-r--r--p2p/src/net/connection_queue.rs10
1 files changed, 5 insertions, 5 deletions
diff --git a/p2p/src/net/connection_queue.rs b/p2p/src/net/connection_queue.rs
index fbc4bfc..4c0de28 100644
--- a/p2p/src/net/connection_queue.rs
+++ b/p2p/src/net/connection_queue.rs
@@ -1,4 +1,4 @@
-use std::sync::Arc;
+use std::{collections::VecDeque, sync::Arc};
use smol::{channel::Sender, lock::Mutex};
@@ -16,14 +16,14 @@ pub struct NewConn {
/// Connection queue
pub struct ConnQueue {
- queue: Mutex<Vec<NewConn>>,
+ queue: Mutex<VecDeque<NewConn>>,
conn_available: CondVar,
}
impl ConnQueue {
pub fn new() -> Arc<Self> {
Arc::new(Self {
- queue: Mutex::new(Vec::new()),
+ queue: Mutex::new(VecDeque::new()),
conn_available: CondVar::new(),
})
}
@@ -36,7 +36,7 @@ impl ConnQueue {
conn,
disconnect_signal,
};
- self.queue.lock().await.push(new_conn);
+ self.queue.lock().await.push_back(new_conn);
self.conn_available.signal();
let _ = chan.recv().await;
}
@@ -47,6 +47,6 @@ impl ConnQueue {
while queue.is_empty() {
queue = self.conn_available.wait(queue).await;
}
- queue.pop().unwrap()
+ queue.pop_front().unwrap()
}
}