stratum: fix check for stop state
This commit is contained in:
parent
114973ecf2
commit
afefa4a7d8
1 changed files with 17 additions and 14 deletions
|
@ -536,20 +536,6 @@ impl Handler {
|
||||||
let mut head = self.chain.head().unwrap();
|
let mut head = self.chain.head().unwrap();
|
||||||
let mut current_hash = head.prev_block_h;
|
let mut current_hash = head.prev_block_h;
|
||||||
loop {
|
loop {
|
||||||
// Ping stratum socket on stop to handle TcpListener unbind.
|
|
||||||
if stop_state.is_stopped() {
|
|
||||||
let listen_addr: SocketAddr = config
|
|
||||||
.stratum_server_addr
|
|
||||||
.clone()
|
|
||||||
.unwrap()
|
|
||||||
.parse()
|
|
||||||
.expect("Stratum: Incorrect address ");
|
|
||||||
thread::spawn(move || {
|
|
||||||
let _ = TcpStream::connect(listen_addr).unwrap();
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the latest chain state
|
// get the latest chain state
|
||||||
head = self.chain.head().unwrap();
|
head = self.chain.head().unwrap();
|
||||||
let latest_hash = head.last_block_h;
|
let latest_hash = head.last_block_h;
|
||||||
|
@ -621,6 +607,8 @@ impl Handler {
|
||||||
fn accept_connections(listen_addr: SocketAddr, handler: Arc<Handler>, stop_state: Arc<StopState>) {
|
fn accept_connections(listen_addr: SocketAddr, handler: Arc<Handler>, stop_state: Arc<StopState>) {
|
||||||
info!("Start tokio stratum server");
|
info!("Start tokio stratum server");
|
||||||
|
|
||||||
|
let state_to_check = stop_state.clone();
|
||||||
|
|
||||||
let task = async move {
|
let task = async move {
|
||||||
let mut listener = TcpListener::bind(&listen_addr).await.unwrap_or_else(|_| {
|
let mut listener = TcpListener::bind(&listen_addr).await.unwrap_or_else(|_| {
|
||||||
panic!("Stratum: Failed to bind to listen address {}", listen_addr)
|
panic!("Stratum: Failed to bind to listen address {}", listen_addr)
|
||||||
|
@ -683,10 +671,25 @@ fn accept_connections(listen_addr: SocketAddr, handler: Arc<Handler>, stop_state
|
||||||
});
|
});
|
||||||
server.await
|
server.await
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut rt = Runtime::new().unwrap();
|
let mut rt = Runtime::new().unwrap();
|
||||||
|
rt.spawn(check_stop_state(state_to_check, listen_addr));
|
||||||
rt.block_on(task);
|
rt.block_on(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn check_stop_state(stop_state: Arc<StopState>, listen_addr: SocketAddr) {
|
||||||
|
loop {
|
||||||
|
// Ping stratum socket on stop to handle TcpListener unbind.
|
||||||
|
if stop_state.is_stopped() {
|
||||||
|
thread::spawn(move || {
|
||||||
|
let _ = TcpStream::connect(listen_addr).unwrap();
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
thread::sleep(Duration::from_millis(1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
// Worker Object - a connected stratum client - a miner, pool, proxy, etc...
|
// Worker Object - a connected stratum client - a miner, pool, proxy, etc...
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue