From 86fd2fdf77057a2408c2017f820e030c0763787b Mon Sep 17 00:00:00 2001 From: xmh0511 <970252187@qq.com> Date: Wed, 17 Jan 2024 19:53:36 +0800 Subject: [PATCH 1/2] associate mtu with the capacity of ReadBuf for all platforms --- src/async/device.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/async/device.rs b/src/async/device.rs index 54967ccf..43b05ab1 100644 --- a/src/async/device.rs +++ b/src/async/device.rs @@ -50,11 +50,12 @@ impl AsyncDevice { } /// Consumes this AsyncDevice and return a Framed object (unified Stream and Sink interface) - pub fn into_framed(mut self) -> Framed { - let packet_information = self.get_mut().has_packet_information(); + pub fn into_framed(self) -> Framed { + let packet_information = self.get_ref().has_packet_information(); let mtu = self.inner.get_ref().mtu().unwrap_or(1504); let codec = TunPacketCodec::new(packet_information, mtu); - Framed::new(self, codec) + // associate mtu with the capacity of ReadBuf + Framed::with_capacity(self, codec, mtu as usize) } } From 199f6758db072e2f30125ea0642a7b9fb39c630a Mon Sep 17 00:00:00 2001 From: xmh0511 <970252187@qq.com> Date: Wed, 17 Jan 2024 19:59:03 +0800 Subject: [PATCH 2/2] change to shared reference --- src/platform/linux/device.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platform/linux/device.rs b/src/platform/linux/device.rs index 126dee90..aa5123c2 100644 --- a/src/platform/linux/device.rs +++ b/src/platform/linux/device.rs @@ -161,7 +161,7 @@ impl Device { } /// Return whether the device has packet information - pub fn has_packet_information(&mut self) -> bool { + pub fn has_packet_information(&self) -> bool { self.queues[0].has_packet_information() } @@ -405,7 +405,7 @@ pub struct Queue { } impl Queue { - pub fn has_packet_information(&mut self) -> bool { + pub fn has_packet_information(&self) -> bool { self.packet_information }