mirror of
https://github.com/dndx/phantun.git
synced 2025-01-18 22:09:30 +08:00
perf(fake-tcp) let the memory allocator zero initialize the BytesMut
memory instead of resizing immediately after allocation
Co-authored-by: Datong Sun <dndx@idndx.com>
This commit is contained in:
parent
f374ac8081
commit
6af7757456
@ -436,8 +436,7 @@ impl Stack {
|
|||||||
let mut tuples: HashMap<AddrTuple, flume::Sender<Bytes>> = HashMap::new();
|
let mut tuples: HashMap<AddrTuple, flume::Sender<Bytes>> = HashMap::new();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let mut buf = BytesMut::with_capacity(MAX_PACKET_LEN);
|
let mut buf = BytesMut::zeroed(MAX_PACKET_LEN);
|
||||||
buf.resize(MAX_PACKET_LEN, 0);
|
|
||||||
|
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
size = tun.recv(&mut buf) => {
|
size = tun.recv(&mut buf) => {
|
||||||
|
@ -47,8 +47,7 @@ pub fn build_tcp_packet(
|
|||||||
let tcp_header_len = TCP_HEADER_LEN + if wscale { 4 } else { 0 }; // nop + wscale
|
let tcp_header_len = TCP_HEADER_LEN + if wscale { 4 } else { 0 }; // nop + wscale
|
||||||
let tcp_total_len = tcp_header_len + payload.map_or(0, |payload| payload.len());
|
let tcp_total_len = tcp_header_len + payload.map_or(0, |payload| payload.len());
|
||||||
let total_len = ip_header_len + tcp_total_len;
|
let total_len = ip_header_len + tcp_total_len;
|
||||||
let mut buf = BytesMut::with_capacity(total_len);
|
let mut buf = BytesMut::zeroed(total_len);
|
||||||
buf.resize(total_len, 0);
|
|
||||||
|
|
||||||
let mut ip_buf = buf.split_to(ip_header_len);
|
let mut ip_buf = buf.split_to(ip_header_len);
|
||||||
let mut tcp_buf = buf.split_to(tcp_total_len);
|
let mut tcp_buf = buf.split_to(tcp_total_len);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user