From a6016c7eeb11fc8aeaa1a3b160b970b15362695d Mon Sep 17 00:00:00 2001 From: hozan23 Date: Sun, 19 May 2024 22:20:03 +0200 Subject: add tokio examples to p2p, jsonrpc, and net crates --- net/src/stream/mod.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'net/src') 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 { inner: T, decoder: C, - buffer: Buffer<[u8; BUFFER_SIZE]>, + buffer: Buffer>, } impl ReadStream @@ -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>, } } @@ -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); -- cgit v1.2.3