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) } } 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 }