mirror of
https://github.com/zhboner/realm.git
synced 2026-11-17 08:15:55 +00:00
adjust buffer size
This commit is contained in:
+5
-5
@@ -14,9 +14,9 @@ cfg_if! {
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(all(target_os = "linux", feature = "zero-copy"))] {
|
||||
const BUFFER_SIZE: usize = 0x10000;
|
||||
const BUF_SIZE: usize = crate::utils::DEFAULT_PIPE_CAP;
|
||||
} else {
|
||||
const BUFFER_SIZE: usize = 0x4000;
|
||||
const BUF_SIZE: usize = crate::utils::DEFAULT_BUF_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ mod normal_copy {
|
||||
where {
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
|
||||
let mut buf = vec![0u8; BUFFER_SIZE];
|
||||
let mut buf = vec![0u8; BUF_SIZE];
|
||||
let mut n: usize;
|
||||
loop {
|
||||
n = timeoutfut(timeout, r.read(&mut buf)).await??;
|
||||
@@ -253,8 +253,8 @@ mod zero_copy {
|
||||
// read until the socket buffer is empty
|
||||
// or the pipe is filled
|
||||
timeoutfut(timeout, rx.readable()).await??;
|
||||
while n < BUFFER_SIZE {
|
||||
match splice_n(rfd, wpipe, BUFFER_SIZE - n) {
|
||||
while n < BUF_SIZE {
|
||||
match splice_n(rfd, wpipe, BUF_SIZE - n) {
|
||||
x if x > 0 => n += x as usize,
|
||||
x if x == 0 => {
|
||||
done = true;
|
||||
|
||||
+4
-3
@@ -9,12 +9,13 @@ use log::{debug, info, error};
|
||||
use tokio::net::UdpSocket;
|
||||
use tokio::time::timeout as timeoutfut;
|
||||
|
||||
use crate::utils::DEFAULT_BUF_SIZE;
|
||||
use crate::utils::{RemoteAddr, ConnectOpts};
|
||||
use crate::utils::{new_sockaddr_v4, new_sockaddr_v6};
|
||||
|
||||
// client <--> allocated socket
|
||||
type SockMap = Arc<RwLock<HashMap<SocketAddr, Arc<UdpSocket>>>>;
|
||||
const BUFFERSIZE: usize = 0x1000;
|
||||
const BUF_SIZE: usize = DEFAULT_BUF_SIZE;
|
||||
|
||||
pub async fn proxy(
|
||||
local: SocketAddr,
|
||||
@@ -29,7 +30,7 @@ pub async fn proxy(
|
||||
let sock_map: SockMap = Arc::new(RwLock::new(HashMap::new()));
|
||||
let local_sock = Arc::new(UdpSocket::bind(&local).await?);
|
||||
let timeout = Duration::from_secs(timeout as u64);
|
||||
let mut buf = vec![0u8; BUFFERSIZE];
|
||||
let mut buf = vec![0u8; BUF_SIZE];
|
||||
|
||||
loop {
|
||||
let (n, client_addr) = match local_sock.recv_from(&mut buf).await {
|
||||
@@ -82,7 +83,7 @@ async fn send_back(
|
||||
alloc_sock: Arc<UdpSocket>,
|
||||
timeout: Duration,
|
||||
) {
|
||||
let mut buf = vec![0u8; BUFFERSIZE];
|
||||
let mut buf = vec![0u8; BUF_SIZE];
|
||||
|
||||
loop {
|
||||
let res =
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// https://github.com/rust-lang/rust/blob/master/library/std/src/sys_common/io.rs#L1
|
||||
pub const DEFAULT_BUF_SIZE: usize = if cfg!(target_os = "espidf") {
|
||||
512
|
||||
} else {
|
||||
8 * 1024
|
||||
};
|
||||
|
||||
// Since Linux 2.6.11, the pipe capacity is 16 pages
|
||||
pub const DEFAULT_PIPE_CAP: usize = 16 * 4096;
|
||||
+3
-1
@@ -1,7 +1,9 @@
|
||||
mod types;
|
||||
|
||||
pub use types::*;
|
||||
|
||||
mod consts;
|
||||
pub use consts::*;
|
||||
|
||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
|
||||
|
||||
#[allow(unused)]
|
||||
|
||||
Reference in New Issue
Block a user