@@ -70,15 +70,14 @@ use std::collections::HashSet;
70
70
use std:: os:: unix:: io:: RawFd ;
71
71
use std:: {
72
72
marker:: PhantomData ,
73
- mem,
74
73
path:: PathBuf ,
75
74
pin:: Pin ,
76
75
sync:: { Arc , Weak } ,
77
76
time:: Duration ,
78
77
} ;
79
- use talpid_core:: split_tunnel;
80
78
use talpid_core:: {
81
79
mpsc:: Sender ,
80
+ split_tunnel,
82
81
tunnel_state_machine:: { self , TunnelCommand , TunnelStateMachineHandle } ,
83
82
} ;
84
83
#[ cfg( target_os = "android" ) ]
@@ -435,49 +434,6 @@ impl From<(AccessMethodEvent, oneshot::Sender<()>)> for InternalDaemonEvent {
435
434
}
436
435
}
437
436
438
- #[ derive( Clone , Debug , Eq , PartialEq ) ]
439
- enum DaemonExecutionState {
440
- Running ,
441
- Exiting ,
442
- Finished ,
443
- }
444
-
445
- impl DaemonExecutionState {
446
- pub fn shutdown ( & mut self , tunnel_state : & TunnelState ) {
447
- use self :: DaemonExecutionState :: * ;
448
-
449
- match self {
450
- Running => {
451
- match tunnel_state {
452
- TunnelState :: Disconnected { .. } => mem:: replace ( self , Finished ) ,
453
- _ => mem:: replace ( self , Exiting ) ,
454
- } ;
455
- }
456
- Exiting | Finished => { }
457
- } ;
458
- }
459
-
460
- pub fn disconnected ( & mut self ) {
461
- use self :: DaemonExecutionState :: * ;
462
-
463
- match self {
464
- Exiting => {
465
- let _ = mem:: replace ( self , Finished ) ;
466
- }
467
- Running | Finished => { }
468
- } ;
469
- }
470
-
471
- pub fn is_running ( & self ) -> bool {
472
- use self :: DaemonExecutionState :: * ;
473
-
474
- match self {
475
- Running => true ,
476
- Exiting | Finished => false ,
477
- }
478
- }
479
- }
480
-
481
437
pub struct DaemonCommandChannel {
482
438
sender : DaemonCommandSender ,
483
439
receiver : mpsc:: UnboundedReceiver < InternalDaemonEvent > ,
@@ -613,7 +569,7 @@ pub trait EventListener {
613
569
pub struct Daemon < L : EventListener > {
614
570
tunnel_state : TunnelState ,
615
571
target_state : PersistentTargetState ,
616
- state : DaemonExecutionState ,
572
+ shutting_down : bool ,
617
573
#[ cfg( target_os = "linux" ) ]
618
574
exclude_pids : split_tunnel:: PidManager ,
619
575
rx : mpsc:: UnboundedReceiver < InternalDaemonEvent > ,
@@ -869,7 +825,7 @@ where
869
825
locked_down : settings. block_when_disconnected ,
870
826
} ,
871
827
target_state,
872
- state : DaemonExecutionState :: Running ,
828
+ shutting_down : false ,
873
829
#[ cfg( target_os = "linux" ) ]
874
830
exclude_pids : split_tunnel:: PidManager :: new ( ) . map_err ( Error :: InitSplitTunneling ) ?,
875
831
rx : internal_event_rx,
@@ -917,7 +873,7 @@ where
917
873
918
874
while let Some ( event) = self . rx . next ( ) . await {
919
875
self . handle_event ( event) . await ;
920
- if self . state == DaemonExecutionState :: Finished {
876
+ if self . shutting_down && self . tunnel_state . is_disconnected ( ) {
921
877
break ;
922
878
}
923
879
}
@@ -1046,7 +1002,6 @@ where
1046
1002
}
1047
1003
1048
1004
match & tunnel_state {
1049
- TunnelState :: Disconnected { .. } => self . state . disconnected ( ) ,
1050
1005
TunnelState :: Connecting { .. } => {
1051
1006
log:: debug!( "Settings: {}" , self . settings. summary( ) ) ;
1052
1007
}
@@ -1183,7 +1138,7 @@ where
1183
1138
1184
1139
async fn handle_command ( & mut self , command : DaemonCommand ) {
1185
1140
use self :: DaemonCommand :: * ;
1186
- if ! self . state . is_running ( ) {
1141
+ if self . shutting_down {
1187
1142
log:: trace!( "Dropping daemon command because the daemon is shutting down" , ) ;
1188
1143
return ;
1189
1144
}
@@ -1462,7 +1417,7 @@ where
1462
1417
tx : oneshot:: Sender < bool > ,
1463
1418
new_target_state : TargetState ,
1464
1419
) {
1465
- if self . state . is_running ( ) {
1420
+ if ! self . shutting_down {
1466
1421
let state_change_initated = self . set_target_state ( new_target_state) . await ;
1467
1422
Self :: oneshot_send ( tx, state_change_initated, "state change initiated" ) ;
1468
1423
} else {
@@ -2692,7 +2647,7 @@ where
2692
2647
self . send_tunnel_command ( TunnelCommand :: BlockWhenDisconnected ( true , tx) ) ;
2693
2648
}
2694
2649
2695
- self . state . shutdown ( & self . tunnel_state ) ;
2650
+ self . shutting_down = true ;
2696
2651
self . disconnect_tunnel ( ) ;
2697
2652
}
2698
2653
0 commit comments