summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSunil Nimmagadda <sunil@nimmagadda.net>2024-11-19 18:46:24 +0530
committerSunil Nimmagadda <sunil@nimmagadda.net>2024-11-19 18:46:24 +0530
commit2bc30a0a2f434ae42fd6711ed2e8fae2726c07b6 (patch)
tree34cdea56de4554db8e570bfd35368c6f6ff9b815 /src
parent49a4934c9dbac13e7019abd8966b367a39b350ba (diff)
Restart from scratch.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs78
1 files changed, 24 insertions, 54 deletions
diff --git a/src/main.rs b/src/main.rs
index 6421bf1..f7eba0b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,58 +1,28 @@
-use tokio::signal::unix;
-use tokio::time;
+// #[derive(Debug)]
+// enum VRRPv2State {
+// Initialize,
+// Backup,
+// Master,
+// }
-const ADV_INTERVAL: u64 = 1;
+// struct StateMachine {
+// state: VRRPv2State,
+// }
-#[derive(Debug)]
-enum VRRPv2State {
- Initialize,
- Backup,
- Master,
-}
-
-struct StateMachine {
- state: VRRPv2State,
-}
-
-impl StateMachine {
- fn new() -> Self {
- StateMachine {
- state: VRRPv2State::Initialize,
- }
- }
- fn transit_to(&mut self, new_state: VRRPv2State) {
- std::println!("vvrpd: {:?} -> {:?}", self.state, new_state);
- self.state = new_state;
- }
-}
-
-async fn advert_handler() {
- println!("advert timer fired");
-}
-
-async fn sighup_handler() {
- println!("got SIGHUP");
-}
+// impl StateMachine {
+// fn new() -> Self {
+// StateMachine {
+// state: VRRPv2State::Initialize,
+// }
+// }
+// fn transit_to(&mut self, new_state: VRRPv2State) {
+// std::println!("vvrpd: {:?} -> {:?}", self.state, new_state);
+// self.state = new_state;
+// }
+// }
-#[tokio::main(flavor = "current_thread")]
-async fn main() {
- let advert_timer_handle = tokio::spawn(async move {
- let mut advert_interval = time::interval(time::Duration::from_secs(ADV_INTERVAL));
- loop {
- advert_interval.tick().await;
- advert_handler().await;
- }
- });
- let sighup_handle = tokio::spawn(async move {
- let mut stream =
- unix::signal(unix::SignalKind::hangup()).expect("Should be a signal stream");
- loop {
- stream.recv().await;
- sighup_handler().await;
- }
- });
- let mut sm = StateMachine::new();
- sm.transit_to(VRRPv2State::Master);
- sm.transit_to(VRRPv2State::Backup);
- tokio::try_join!(advert_timer_handle, sighup_handle).expect("task(s) erred");
+fn main() {
+ // let mut sm = StateMachine::new();
+ // sm.transit_to(VRRPv2State::Master);
+ // sm.transit_to(VRRPv2State::Backup);
}