@@ -59,12 +59,15 @@ use crate::stratum::Stratum;
59
59
use crate :: stratum_rpc:: StratumRpc ;
60
60
use crate :: util:: to_base64;
61
61
use crate :: util:: RwLock ;
62
+ use crate :: util:: StopState ;
62
63
use crate :: web:: * ;
63
64
use easy_jsonrpc_mw:: { Handler , MaybeReply } ;
65
+ use futures:: channel:: oneshot;
64
66
use hyper:: { Body , Request , Response , StatusCode } ;
65
67
use serde:: Serialize ;
66
68
use std:: net:: SocketAddr ;
67
69
use std:: sync:: { Arc , Weak } ;
70
+ use std:: thread;
68
71
69
72
/// Listener version, providing same API but listening for requests on a
70
73
/// port and wrapping the calls
@@ -79,6 +82,8 @@ pub fn node_apis<B, P, V>(
79
82
tls_config : Option < TLSConfig > ,
80
83
allow_to_stop : bool ,
81
84
stratum_ip_pool : Arc < stratum:: connections:: StratumIpPool > ,
85
+ api_chan : & ' static mut ( oneshot:: Sender < ( ) > , oneshot:: Receiver < ( ) > ) ,
86
+ stop_state : Arc < StopState > ,
82
87
) -> Result < ( ) , Error >
83
88
where
84
89
B : BlockChain + ' static ,
@@ -155,10 +160,24 @@ where
155
160
let mut apis = ApiServer :: new ( ) ;
156
161
warn ! ( "Starting HTTP Node APIs server at {}." , addr) ;
157
162
let socket_addr: SocketAddr = addr. parse ( ) . expect ( "unable to parse socket address" ) ;
158
- let api_thread = apis. start ( socket_addr, router, tls_config) ;
163
+ let api_thread = apis. start ( socket_addr, router, tls_config, api_chan ) ;
159
164
160
165
warn ! ( "HTTP Node listener started." ) ;
161
166
167
+ thread:: Builder :: new ( )
168
+ . name ( "api_monitor" . to_string ( ) )
169
+ . spawn ( move || {
170
+ // monitor for stop state is_stopped
171
+ loop {
172
+ std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 100 ) ) ;
173
+ if stop_state. is_stopped ( ) {
174
+ apis. stop ( ) ;
175
+ break ;
176
+ }
177
+ }
178
+ } )
179
+ . ok ( ) ;
180
+
162
181
match api_thread {
163
182
Ok ( _) => Ok ( ( ) ) ,
164
183
Err ( e) => {
0 commit comments