Fix proxy read timeout

This commit is contained in:
Dennis Schwerdel 2022-09-23 23:24:08 +02:00
parent ca4ad2769d
commit 89d058134e
2 changed files with 9 additions and 3 deletions

View File

@ -7,8 +7,8 @@
- [x] Check how async affects performance
- [x] Sync traffic stats
- [x] Sync forwarding table
- [ ] Fix WS Proxy code
- [ ] Fix Ctrl-C
- [x] Fix WS Proxy code
- [x] Fix Ctrl-C
- [x] Fix auto-claim IP
## REST API

View File

@ -13,7 +13,7 @@ use std::{
io::{self, Cursor, Read, Write},
net::{Ipv6Addr, SocketAddr, SocketAddrV6, TcpListener, TcpStream, UdpSocket},
os::unix::io::{AsRawFd, RawFd},
thread,
thread, time::Duration,
};
use tungstenite::{
accept, connect,
@ -122,6 +122,12 @@ impl ProxyConnection {
let parsed_url = io_error!(Url::parse(url), "Invalid URL {}: {}", url)?;
let (mut socket, _) = io_error!(connect(parsed_url), "Failed to connect to URL {}: {}", url)?;
socket.get_mut().set_nodelay(true)?;
match socket.get_mut() {
&mut MaybeTlsStream::Plain(ref mut stream) => {
io_error!(stream.set_read_timeout(Some(Duration::from_secs(1))), "Failed to set read timeout: {}")?
},
_ => unimplemented!()
}
let addr = "0.0.0.0:0".parse::<SocketAddr>().unwrap();
let mut con = ProxyConnection { addr, socket };
let addr_data = con.read_message()?;