@@ -38,11 +38,9 @@ use crate::local::{
38
38
39
39
use super :: virt_device:: VirtTunDevice ;
40
40
41
- // NOTE: Default value is taken from Linux
42
- // recv: /proc/sys/net/ipv4/tcp_rmem 87380 bytes
43
- // send: /proc/sys/net/ipv4/tcp_wmem 16384 bytes
44
- const DEFAULT_TCP_SEND_BUFFER_SIZE : u32 = 16384 ;
45
- const DEFAULT_TCP_RECV_BUFFER_SIZE : u32 = 87380 ;
41
+ // NOTE: Default buffer could contain 20 AEAD packets
42
+ const DEFAULT_TCP_SEND_BUFFER_SIZE : u32 = 0x3FFF * 20 ;
43
+ const DEFAULT_TCP_RECV_BUFFER_SIZE : u32 = 0x3FFF * 20 ;
46
44
47
45
struct TcpSocketControl {
48
46
send_buffer : RingBuffer < ' static , u8 > ,
@@ -147,7 +145,9 @@ impl AsyncRead for TcpConnection {
147
145
let n = control. recv_buffer . dequeue_slice ( recv_buf) ;
148
146
buf. advance ( n) ;
149
147
150
- self . manager_notify . notify ( ) ;
148
+ if control. recv_buffer . is_empty ( ) {
149
+ self . manager_notify . notify ( ) ;
150
+ }
151
151
Ok ( ( ) ) . into ( )
152
152
}
153
153
}
@@ -173,7 +173,9 @@ impl AsyncWrite for TcpConnection {
173
173
174
174
let n = control. send_buffer . enqueue_slice ( buf) ;
175
175
176
- self . manager_notify . notify ( ) ;
176
+ if control. send_buffer . is_full ( ) {
177
+ self . manager_notify . notify ( ) ;
178
+ }
177
179
Ok ( n) . into ( )
178
180
}
179
181
@@ -207,7 +209,7 @@ pub struct TcpTun {
207
209
manager_running : Arc < AtomicBool > ,
208
210
balancer : PingBalancer ,
209
211
iface_rx : mpsc:: UnboundedReceiver < Vec < u8 > > ,
210
- iface_tx : mpsc:: Sender < Vec < u8 > > ,
212
+ iface_tx : mpsc:: UnboundedSender < Vec < u8 > > ,
211
213
}
212
214
213
215
impl Drop for TcpTun {
@@ -278,10 +280,8 @@ impl TcpTun {
278
280
}
279
281
} ;
280
282
281
- let after_poll = SmolInstant :: now ( ) ;
282
-
283
283
if updated_sockets {
284
- trace ! ( "VirtDevice::poll costed {}" , after_poll - before_poll) ;
284
+ trace ! ( "VirtDevice::poll costed {}" , SmolInstant :: now ( ) - before_poll) ;
285
285
}
286
286
287
287
// Check all the sockets' status
@@ -377,11 +377,8 @@ impl TcpTun {
377
377
iface. remove_socket ( socket_handle) ;
378
378
}
379
379
380
- let next_duration = iface
381
- . poll_delay ( SmolInstant :: now ( ) )
382
- . unwrap_or ( SmolDuration :: from_millis ( 1 ) ) ;
383
-
384
- if next_duration. total_millis ( ) != 0 {
380
+ let next_duration = iface. poll_delay ( before_poll) . unwrap_or ( SmolDuration :: from_millis ( 5 ) ) ;
381
+ if next_duration != SmolDuration :: ZERO {
385
382
thread:: park_timeout ( Duration :: from ( next_duration) ) ;
386
383
}
387
384
}
@@ -422,10 +419,10 @@ impl TcpTun {
422
419
TcpSocketBuffer :: new ( vec ! [ 0u8 ; send_buffer_size as usize ] ) ,
423
420
) ;
424
421
socket. set_keep_alive ( accept_opts. tcp . keepalive . map ( From :: from) ) ;
425
- // FIXME: This should follows system's setting. 7200 is Linux's default.
422
+ // FIXME: It should follow system's setting. 7200 is Linux's default.
426
423
socket. set_timeout ( Some ( SmolDuration :: from_secs ( 7200 ) ) ) ;
427
424
// NO ACK delay
428
- socket. set_ack_delay ( None ) ;
425
+ // socket.set_ack_delay(None);
429
426
430
427
if let Err ( err) = socket. listen ( dst_addr) {
431
428
return Err ( io:: Error :: new ( ErrorKind :: Other , err) ) ;
@@ -454,7 +451,7 @@ impl TcpTun {
454
451
}
455
452
456
453
pub async fn drive_interface_state ( & mut self , frame : & [ u8 ] ) {
457
- if let Err ( ..) = self . iface_tx . send ( frame. to_vec ( ) ) . await {
454
+ if let Err ( ..) = self . iface_tx . send ( frame. to_vec ( ) ) {
458
455
panic ! ( "interface send channel closed unexpectly" ) ;
459
456
}
460
457
0 commit comments