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