Fix atomicity violation in network-devp2p (#11277)

This commit is contained in:
Boqin Qin 2019-12-10 01:46:32 -05:00 committed by David
parent 4c6b282bee
commit f1f64930cf

View File

@ -220,14 +220,13 @@ impl Connection {
/// Register this connection with the IO event loop. /// Register this connection with the IO event loop.
pub fn register_socket<Host: Handler>(&self, reg: Token, event_loop: &mut EventLoop<Host>) -> io::Result<()> { pub fn register_socket<Host: Handler>(&self, reg: Token, event_loop: &mut EventLoop<Host>) -> io::Result<()> {
if self.registered.load(AtomicOrdering::SeqCst) { if self.registered.compare_and_swap(false, true, AtomicOrdering::SeqCst) {
return Ok(()); return Ok(());
} }
trace!(target: "network", "connection register; token={:?}", reg); trace!(target: "network", "connection register; token={:?}", reg);
if let Err(e) = event_loop.register(&self.socket, reg, self.interest, PollOpt::edge() /* | PollOpt::oneshot() */) { // TODO: oneshot is broken on windows if let Err(e) = event_loop.register(&self.socket, reg, self.interest, PollOpt::edge() /* | PollOpt::oneshot() */) { // TODO: oneshot is broken on windows
trace!(target: "network", "Failed to register {:?}, {:?}", reg, e); trace!(target: "network", "Failed to register {:?}, {:?}", reg, e);
} }
self.registered.store(true, AtomicOrdering::SeqCst);
Ok(()) Ok(())
} }