summaryrefslogtreecommitdiffstats
path: root/src/configuration/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/configuration/config.rs')
-rw-r--r--src/configuration/config.rs17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/configuration/config.rs b/src/configuration/config.rs
index d61cda5..59cef4a 100644
--- a/src/configuration/config.rs
+++ b/src/configuration/config.rs
@@ -1,3 +1,4 @@
+use std::mem;
use std::net::{IpAddr, SocketAddr};
use std::sync::atomic::Ordering;
use std::sync::{Arc, Mutex, MutexGuard};
@@ -266,24 +267,22 @@ impl<T: tun::Tun, B: udp::PlatformUDP> Configuration for WireGuardConfig<T, B> {
fn set_listen_port(&self, port: u16) -> Result<(), ConfigError> {
log::trace!("Config, Set listen port: {:?}", port);
- // update port
- let listen: bool = {
+ // update port and take old bind
+ let old: Option<B::Owner> = {
let mut cfg = self.lock();
+ let old = mem::replace(&mut cfg.bind, None);
cfg.port = port;
- if cfg.bind.is_some() {
- cfg.bind = None;
- true
- } else {
- false
- }
+ old
};
// restart listener if bound
- if listen {
+ if old.is_some() {
self.start_listener()
} else {
Ok(())
}
+
+ // old bind is dropped, causing the file-descriptors to be released
}
fn set_fwmark(&self, mark: Option<u32>) -> Result<(), ConfigError> {