mirror of https://github.com/dswd/vpncloud.git
Template
This commit is contained in:
parent
ff40f47b52
commit
5000066646
|
@ -0,0 +1,33 @@
|
|||
use std::{marker::PhantomData, sync::Arc};
|
||||
|
||||
use super::shared::SharedData;
|
||||
use crate::{
|
||||
device::Device,
|
||||
util::{Time, TimeSource}
|
||||
};
|
||||
|
||||
|
||||
const SYNC_INTERVAL: Time = 1;
|
||||
|
||||
pub struct DeviceThread<D: Device, T: TimeSource> {
|
||||
shared: Arc<SharedData>,
|
||||
device: D,
|
||||
next_sync: Time,
|
||||
_dummy: PhantomData<T>
|
||||
}
|
||||
|
||||
impl<D: Device, T: TimeSource> DeviceThread<D, T> {
|
||||
fn sync(&mut self) {
|
||||
// TODO sync
|
||||
}
|
||||
|
||||
pub fn run(mut self) {
|
||||
loop {
|
||||
let now = T::now();
|
||||
if self.next_sync < now {
|
||||
self.sync();
|
||||
self.next_sync = now + SYNC_INTERVAL
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,10 @@
|
|||
// Copyright (C) 2015-2020 Dennis Schwerdel
|
||||
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||
|
||||
mod device_thread;
|
||||
mod socket_thread;
|
||||
mod shared;
|
||||
|
||||
use std::{
|
||||
cmp::{max, min},
|
||||
collections::HashMap,
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
pub struct SharedData {}
|
|
@ -0,0 +1,32 @@
|
|||
use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::shared::SharedData;
|
||||
use crate::net::Socket;
|
||||
use crate::util::{Time, TimeSource};
|
||||
|
||||
|
||||
const SYNC_INTERVAL: Time = 1;
|
||||
|
||||
pub struct SocketThread<S: Socket, T: TimeSource> {
|
||||
shared: Arc<SharedData>,
|
||||
socket: S,
|
||||
next_sync: Time,
|
||||
_dummy: PhantomData<T>
|
||||
}
|
||||
|
||||
impl<S: Socket, T: TimeSource> SocketThread<S, T> {
|
||||
fn sync(&mut self) {
|
||||
//TODO sync
|
||||
}
|
||||
|
||||
pub fn run(mut self) {
|
||||
loop {
|
||||
let now = T::now();
|
||||
if self.next_sync < now {
|
||||
self.sync();
|
||||
self.next_sync = now + SYNC_INTERVAL
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue