Clean up exit signal handling
This commit is contained in:
parent
1c0cfb17a3
commit
bd39ab9365
|
@ -34,7 +34,7 @@ impl LocalVoteSignerService {
|
|||
let thread = Builder::new()
|
||||
.name("solana-vote-signer".to_string())
|
||||
.spawn(move || {
|
||||
let service = VoteSignerRpcService::new(addr, thread_exit);
|
||||
let service = VoteSignerRpcService::new(addr, &thread_exit);
|
||||
service.join().unwrap();
|
||||
})
|
||||
.unwrap();
|
||||
|
|
|
@ -31,10 +31,9 @@ fn main() -> Result<(), Box<error::Error>> {
|
|||
let exit = Arc::new(AtomicBool::new(false));
|
||||
let service = VoteSignerRpcService::new(
|
||||
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), port),
|
||||
exit,
|
||||
&exit,
|
||||
);
|
||||
|
||||
service.join().unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -14,13 +14,12 @@ use std::time::Duration;
|
|||
|
||||
pub struct VoteSignerRpcService {
|
||||
thread_hdl: JoinHandle<()>,
|
||||
exit: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
impl VoteSignerRpcService {
|
||||
pub fn new(rpc_addr: SocketAddr, exit: Arc<AtomicBool>) -> Self {
|
||||
pub fn new(rpc_addr: SocketAddr, exit: &Arc<AtomicBool>) -> Self {
|
||||
let request_processor = LocalVoteSigner::default();
|
||||
let exit_ = exit.clone();
|
||||
let exit = exit.clone();
|
||||
let thread_hdl = Builder::new()
|
||||
.name("solana-vote-signer-jsonrpc".to_string())
|
||||
.spawn(move || {
|
||||
|
@ -40,22 +39,13 @@ impl VoteSignerRpcService {
|
|||
warn!("JSON RPC service unavailable: unable to bind to RPC port {}. \nMake sure this port is not already in use by another application", rpc_addr.port());
|
||||
return;
|
||||
}
|
||||
while !exit_.load(Ordering::Relaxed) {
|
||||
while !exit.load(Ordering::Relaxed) {
|
||||
sleep(Duration::from_millis(100));
|
||||
}
|
||||
server.unwrap().close();
|
||||
})
|
||||
.unwrap();
|
||||
Self { thread_hdl, exit }
|
||||
}
|
||||
|
||||
pub fn exit(&self) {
|
||||
self.exit.store(true, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
pub fn close(self) -> thread::Result<()> {
|
||||
self.exit();
|
||||
self.join()
|
||||
Self { thread_hdl }
|
||||
}
|
||||
|
||||
pub fn join(self) -> thread::Result<()> {
|
||||
|
|
Loading…
Reference in New Issue