Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Remove the error when stopping the network
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaka committed May 20, 2018
1 parent 6552256 commit 6a26f8d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
6 changes: 2 additions & 4 deletions ethcore/sync/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ impl ChainNotify for EthSync {

fn stop(&self) {
self.eth_handler.snapshot_service.abort_restore();
self.network.stop().unwrap_or_else(|e| warn!("Error stopping network: {:?}", e));
self.network.stop();
}

fn broadcast(&self, message_type: ChainMessageType) {
Expand Down Expand Up @@ -832,9 +832,7 @@ impl ManageNetwork for LightSync {

fn stop_network(&self) {
self.proto.abort();
if let Err(e) = self.network.stop() {
warn!("Error stopping network: {}", e);
}
self.network.stop();
}

fn network_config(&self) -> NetworkConfiguration {
Expand Down
10 changes: 6 additions & 4 deletions util/io/src/service_mio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,13 @@ impl<Message> IoContext<Message> where Message: Send + Sync + 'static {
}

/// Unregister current IO handler.
pub fn unregister_handler(&self) -> Result<(), IoError> {
self.channel.send_io(IoMessage::RemoveHandler {
pub fn unregister_handler(&self) {
// `send_io` returns an error only if the channel is closed, which means that the
// background thread is no longer running. Therefore the handler is no longer active and
// can be considered as unregistered.
let _ = self.channel.send_io(IoMessage::RemoveHandler {
handler_id: self.handler,
})?;
Ok(())
});
}

}
Expand Down
5 changes: 2 additions & 3 deletions util/network-devp2p/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ impl Host {
format!("{}", Node::new(info.id().clone(), info.local_endpoint.clone()))
}

pub fn stop(&self, io: &IoContext<NetworkIoMessage>) -> Result<(), Error> {
pub fn stop(&self, io: &IoContext<NetworkIoMessage>) {
self.stopping.store(true, AtomicOrdering::Release);
let mut to_kill = Vec::new();
for e in self.sessions.read().iter() {
Expand All @@ -408,8 +408,7 @@ impl Host {
trace!(target: "network", "Disconnecting on shutdown: {}", p);
self.kill_connection(p, io, true);
}
io.unregister_handler()?;
Ok(())
io.unregister_handler();
}

/// Get all connected peers.
Expand Down
7 changes: 3 additions & 4 deletions util/network-devp2p/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,14 @@ impl NetworkService {
Ok(())
}

/// Stop network IO
pub fn stop(&self) -> Result<(), Error> {
/// Stop network IO.
pub fn stop(&self) {
let mut host = self.host.write();
if let Some(ref host) = *host {
let io = IoContext::new(self.io_service.channel(), 0); //TODO: take token id from host
host.stop(&io)?;
host.stop(&io);
}
*host = None;
Ok(())
}

/// Get a list of all connected peers by id.
Expand Down

0 comments on commit 6a26f8d

Please sign in to comment.