mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-04-24 07:46:03 +00:00
remove_connection refactor
This commit is contained in:
parent
8b014322fc
commit
ef6f67b975
1 changed files with 7 additions and 6 deletions
|
@ -257,9 +257,8 @@ impl<'a> TunToProxy<'a> {
|
||||||
.register(&mut exit_receiver, EXIT_TOKEN, Interest::READABLE)?;
|
.register(&mut exit_receiver, EXIT_TOKEN, Interest::READABLE)?;
|
||||||
|
|
||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
#[rustfmt::skip]
|
|
||||||
let config = match tun.capabilities().medium {
|
let config = match tun.capabilities().medium {
|
||||||
Medium::Ethernet => Config::new(smoltcp::wire::EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x01]).into()),
|
Medium::Ethernet => Config::new(smoltcp::wire::EthernetAddress([0x02, 0, 0, 0, 0, 0x01]).into()),
|
||||||
Medium::Ip => Config::new(smoltcp::wire::HardwareAddress::Ip),
|
Medium::Ip => Config::new(smoltcp::wire::HardwareAddress::Ip),
|
||||||
Medium::Ieee802154 => todo!(),
|
Medium::Ieee802154 => todo!(),
|
||||||
};
|
};
|
||||||
|
@ -350,16 +349,14 @@ impl<'a> TunToProxy<'a> {
|
||||||
/// Destroy connection state machine
|
/// Destroy connection state machine
|
||||||
fn remove_connection(&mut self, info: &ConnectionInfo) -> Result<(), Error> {
|
fn remove_connection(&mut self, info: &ConnectionInfo) -> Result<(), Error> {
|
||||||
if let Some(mut state) = self.connection_map.remove(info) {
|
if let Some(mut state) = self.connection_map.remove(info) {
|
||||||
_ = state.mio_stream.shutdown(Shutdown::Both);
|
self.expect_smoltcp_send()?;
|
||||||
|
|
||||||
if let Some(handle) = state.smoltcp_handle {
|
if let Some(handle) = state.smoltcp_handle {
|
||||||
let socket = self.sockets.get_mut::<tcp::Socket>(handle);
|
let socket = self.sockets.get_mut::<tcp::Socket>(handle);
|
||||||
socket.close();
|
socket.close();
|
||||||
self.sockets.remove(handle);
|
self.sockets.remove(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Does this line should be moved up to the beginning of this function?
|
|
||||||
self.expect_smoltcp_send()?;
|
|
||||||
|
|
||||||
if let Err(e) = self.poll.registry().deregister(&mut state.mio_stream) {
|
if let Err(e) = self.poll.registry().deregister(&mut state.mio_stream) {
|
||||||
// FIXME: The function `deregister` will frequently fail for unknown reasons.
|
// FIXME: The function `deregister` will frequently fail for unknown reasons.
|
||||||
log::trace!("{}", e);
|
log::trace!("{}", e);
|
||||||
|
@ -371,6 +368,10 @@ impl<'a> TunToProxy<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Err(err) = state.mio_stream.shutdown(Shutdown::Both) {
|
||||||
|
log::debug!("Shutdown {} error \"{}\"", info, err);
|
||||||
|
}
|
||||||
|
|
||||||
log::info!("Close {}", info);
|
log::info!("Close {}", info);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Add table
Reference in a new issue