mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-06-09 16:17:45 +00:00
Fix CPU spikes due to always-writable event and improve half-open connection handling
This commit is contained in:
parent
0be39345a8
commit
10a674d1c9
3 changed files with 143 additions and 59 deletions
|
@ -1,7 +1,7 @@
|
|||
use crate::error::Error;
|
||||
use crate::tun2proxy::{
|
||||
Connection, ConnectionManager, DestinationHost, IncomingDataEvent, IncomingDirection,
|
||||
OutgoingDataEvent, OutgoingDirection, TcpProxy,
|
||||
Connection, ConnectionManager, DestinationHost, Direction, IncomingDataEvent,
|
||||
IncomingDirection, OutgoingDataEvent, OutgoingDirection, TcpProxy,
|
||||
};
|
||||
use crate::Credentials;
|
||||
use smoltcp::wire::IpProtocol;
|
||||
|
@ -368,6 +368,21 @@ impl TcpProxy for SocksConnection {
|
|||
fn connection_established(&self) -> bool {
|
||||
self.state == SocksState::Established
|
||||
}
|
||||
|
||||
fn have_data(&mut self, dir: Direction) -> bool {
|
||||
match dir {
|
||||
Direction::Incoming(incoming) => match incoming {
|
||||
IncomingDirection::FromServer => self.server_inbuf.len() > 0,
|
||||
IncomingDirection::FromClient => {
|
||||
self.client_inbuf.len() > 0 || self.data_buf.len() > 0
|
||||
}
|
||||
},
|
||||
Direction::Outgoing(outgoing) => match outgoing {
|
||||
OutgoingDirection::ToServer => self.server_outbuf.len() > 0,
|
||||
OutgoingDirection::ToClient => self.client_outbuf.len() > 0,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SocksManager {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue