aboutsummaryrefslogtreecommitdiff
path: root/net/src
diff options
context:
space:
mode:
authorhozan23 <hozan23@karyontech.net>2024-05-19 22:20:03 +0200
committerhozan23 <hozan23@karyontech.net>2024-05-19 22:20:03 +0200
commita6016c7eeb11fc8aeaa1a3b160b970b15362695d (patch)
treea872c02076836811257b59ce7d88f9ef5a85f5ed /net/src
parent1c520b20f70ddbdab885ec6c4bf5c87893a26eb4 (diff)
add tokio examples to p2p, jsonrpc, and net crates
Diffstat (limited to 'net/src')
-rw-r--r--net/src/stream/mod.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/net/src/stream/mod.rs b/net/src/stream/mod.rs
index 9493b29..b792292 100644
--- a/net/src/stream/mod.rs
+++ b/net/src/stream/mod.rs
@@ -25,13 +25,13 @@ use crate::{
use buffer::Buffer;
-const BUFFER_SIZE: usize = 2048 * 2024; // 4MB
+const BUFFER_SIZE: usize = 2048 * 2048; // 4MB
const INITIAL_BUFFER_SIZE: usize = 1024 * 1024; // 1MB
pub struct ReadStream<T, C> {
inner: T,
decoder: C,
- buffer: Buffer<[u8; BUFFER_SIZE]>,
+ buffer: Buffer<Vec<u8>>,
}
impl<T, C> ReadStream<T, C>
@@ -43,7 +43,7 @@ where
Self {
inner,
decoder,
- buffer: Buffer::new([0u8; BUFFER_SIZE]),
+ buffer: Buffer::new(vec![0u8; BUFFER_SIZE]),
}
}
@@ -61,7 +61,7 @@ pin_project! {
inner: T,
encoder: C,
high_water_mark: usize,
- buffer: Buffer<[u8; BUFFER_SIZE]>,
+ buffer: Buffer<Vec<u8>>,
}
}
@@ -75,7 +75,7 @@ where
inner,
encoder,
high_water_mark: 131072,
- buffer: Buffer::new([0u8; BUFFER_SIZE]),
+ buffer: Buffer::new(vec![0u8; BUFFER_SIZE]),
}
}
}
@@ -114,6 +114,9 @@ where
this.buffer.extend_from_slice(bytes);
+ #[cfg(feature = "tokio")]
+ buf.clear();
+
match this.decoder.decode(this.buffer.as_mut())? {
Some((cn, item)) => {
this.buffer.advance(cn);