Fixed network service dispose
This commit is contained in:
parent
bf6308312e
commit
4b3f23f0ac
@ -14,7 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::{Arc, Weak};
|
||||||
use ethcore::client::Client;
|
use ethcore::client::Client;
|
||||||
use ethcore::service::{NetSyncMessage, SyncMessage};
|
use ethcore::service::{NetSyncMessage, SyncMessage};
|
||||||
use ethsync::EthSync;
|
use ethsync::EthSync;
|
||||||
@ -30,7 +30,7 @@ pub struct ClientIoHandler {
|
|||||||
pub sync: Arc<EthSync>,
|
pub sync: Arc<EthSync>,
|
||||||
pub accounts: Arc<AccountProvider>,
|
pub accounts: Arc<AccountProvider>,
|
||||||
pub info: Informant,
|
pub info: Informant,
|
||||||
pub network: Arc<NetworkService<SyncMessage>>,
|
pub network: Weak<NetworkService<SyncMessage>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IoHandler<NetSyncMessage> for ClientIoHandler {
|
impl IoHandler<NetSyncMessage> for ClientIoHandler {
|
||||||
@ -49,12 +49,16 @@ impl IoHandler<NetSyncMessage> for ClientIoHandler {
|
|||||||
match *message {
|
match *message {
|
||||||
NetworkIoMessage::User(SyncMessage::StartNetwork) => {
|
NetworkIoMessage::User(SyncMessage::StartNetwork) => {
|
||||||
info!("Starting network");
|
info!("Starting network");
|
||||||
self.network.start().unwrap_or_else(|e| warn!("Error starting network: {:?}", e));
|
if let Some(network) = self.network.upgrade() {
|
||||||
EthSync::register(&*self.network, self.sync.clone()).unwrap_or_else(|e| warn!("Error registering eth protocol handler: {}", e));
|
network.start().unwrap_or_else(|e| warn!("Error starting network: {:?}", e));
|
||||||
|
EthSync::register(&*network, self.sync.clone()).unwrap_or_else(|e| warn!("Error registering eth protocol handler: {}", e));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
NetworkIoMessage::User(SyncMessage::StopNetwork) => {
|
NetworkIoMessage::User(SyncMessage::StopNetwork) => {
|
||||||
info!("Stopping network");
|
info!("Stopping network");
|
||||||
self.network.stop().unwrap_or_else(|e| warn!("Error stopping network: {:?}", e));
|
if let Some(network) = self.network.upgrade() {
|
||||||
|
network.stop().unwrap_or_else(|e| warn!("Error stopping network: {:?}", e));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_ => {/* Ignore other messages */},
|
_ => {/* Ignore other messages */},
|
||||||
}
|
}
|
||||||
|
@ -272,7 +272,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig)
|
|||||||
info: Informant::new(conf.have_color()),
|
info: Informant::new(conf.have_color()),
|
||||||
sync: sync.clone(),
|
sync: sync.clone(),
|
||||||
accounts: account_service.clone(),
|
accounts: account_service.clone(),
|
||||||
network: service.network(),
|
network: Arc::downgrade(&service.network()),
|
||||||
});
|
});
|
||||||
service.register_io_handler(io_handler).expect("Error registering IO handler");
|
service.register_io_handler(io_handler).expect("Error registering IO handler");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user