Skip to content
This repository has been archived by the owner on Oct 27, 2024. It is now read-only.

Commit

Permalink
Fix #91
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrlive committed Jul 25, 2024
1 parent ed0a23a commit 25fc58a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tun2"
version = "2.0.4"
version = "2.0.5"
edition = "2021"
authors = ["meh. <[email protected]>", "@ssrlive"]
license = "WTFPL"
Expand Down
16 changes: 12 additions & 4 deletions src/platform/posix/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,14 @@ impl Reader {
// The following logic is to prevent dynamically allocating Vec on every recv
// As long as the MTU is set to value lesser than 1500, this api uses `stack_buf`
// and avoids `Vec` allocation
let mut dynamic_buf: Vec<u8>;
let mut fixed_buf: [u8; STACK_BUF_LEN];
let local_buf = if in_buf_len > STACK_BUF_LEN && self.offset != 0 {
&mut vec![0u8; in_buf_len][..]
dynamic_buf = vec![0u8; in_buf_len];
&mut dynamic_buf[..]
} else {
&mut [0u8; STACK_BUF_LEN]
fixed_buf = [0u8; STACK_BUF_LEN];
&mut fixed_buf
};

let either_buf = if self.offset != 0 {
Expand Down Expand Up @@ -149,10 +153,14 @@ impl Writer {
// The following logic is to prevent dynamically allocating Vec on every send
// As long as the MTU is set to value lesser than 1500, this api uses `stack_buf`
// and avoids `Vec` allocation
let mut dynamic_buf: Vec<u8>;
let mut fixed_buf: [u8; STACK_BUF_LEN];
let local_buf = if in_buf_len > STACK_BUF_LEN && self.offset != 0 {
&mut vec![0u8; in_buf_len][..]
dynamic_buf = vec![0_u8; in_buf_len];
&mut dynamic_buf[..]
} else {
&mut [0u8; STACK_BUF_LEN]
fixed_buf = [0_u8; STACK_BUF_LEN];
&mut fixed_buf
};

let either_buf = if self.offset != 0 {
Expand Down

0 comments on commit 25fc58a

Please sign in to comment.