diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2019-10-31 17:11:09 +0100 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2019-10-31 17:11:09 +0100 |
commit | b25c21885bf97e74802549e3ac22f57bc0c44d76 (patch) | |
tree | d35eb556666846045e434e27f91648fa94bebd46 /src/wireguard/endpoint.rs | |
parent | Remove unused dependencies (diff) | |
download | wireguard-rs-b25c21885bf97e74802549e3ac22f57bc0c44d76.tar.xz wireguard-rs-b25c21885bf97e74802549e3ac22f57bc0c44d76.zip |
Work on timer semantics
Diffstat (limited to 'src/wireguard/endpoint.rs')
-rw-r--r-- | src/wireguard/endpoint.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/wireguard/endpoint.rs b/src/wireguard/endpoint.rs new file mode 100644 index 0000000..f6a560b --- /dev/null +++ b/src/wireguard/endpoint.rs @@ -0,0 +1,29 @@ +use spin::{Mutex, MutexGuard}; +use std::sync::Arc; + +use super::super::platform::Endpoint; + +#[derive(Clone)] +struct EndpointStore<E: Endpoint> { + endpoint: Arc<Mutex<Option<E>>>, +} + +impl<E: Endpoint> EndpointStore<E> { + pub fn new() -> EndpointStore<E> { + EndpointStore { + endpoint: Arc::new(Mutex::new(None)), + } + } + + pub fn set(&self, endpoint: E) { + *self.endpoint.lock() = Some(endpoint); + } + + pub fn get(&self) -> MutexGuard<Option<E>> { + self.endpoint.lock() + } + + pub fn clear_src(&self) { + (*self.endpoint.lock()).as_mut().map(|e| e.clear_src()); + } +} |