From 83320efa31a4c3e7eaf2302d1322a1932a3102d7 Mon Sep 17 00:00:00 2001 From: Dany Laporte Date: Wed, 26 Feb 2020 04:40:31 -0500 Subject: [PATCH] Avoid error by `register()` on Windows (#103) --- actix-server/src/accept.rs | 46 ++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/actix-server/src/accept.rs b/actix-server/src/accept.rs index 993ecab4..4dc218fd 100644 --- a/actix-server/src/accept.rs +++ b/actix-server/src/accept.rs @@ -298,12 +298,7 @@ impl Accept { } Command::Resume => { for (token, info) in self.sockets.iter() { - if let Err(err) = self.poll.register( - &info.sock, - mio::Token(token + DELTA), - mio::Ready::readable(), - mio::PollOpt::edge(), - ) { + if let Err(err) = self.register(token, info) { error!("Can not resume socket accept process: {}", err); } else { info!( @@ -338,17 +333,44 @@ impl Accept { true } + #[cfg(not(target_os = "windows"))] + fn register(&self, token: usize, info: &ServerSocketInfo) -> io::Result<()> { + self.poll.register( + &info.sock, + mio::Token(token + DELTA), + mio::Ready::readable(), + mio::PollOpt::edge(), + ) + } + + #[cfg(target_os = "windows")] + fn register(&self, token: usize, info: &ServerSocketInfo) -> io::Result<()> { + // On windows, calling register without deregister cause an error. + // See https://github.com/actix/actix-web/issues/905 + // Calling reregister seems to fix the issue. + self.poll + .register( + &info.sock, + mio::Token(token + DELTA), + mio::Ready::readable(), + mio::PollOpt::edge(), + ) + .or_else(|_| { + self.poll.reregister( + &info.sock, + mio::Token(token + DELTA), + mio::Ready::readable(), + mio::PollOpt::edge(), + ) + }) + } + fn backpressure(&mut self, on: bool) { if self.backpressure { if !on { self.backpressure = false; for (token, info) in self.sockets.iter() { - if let Err(err) = self.poll.register( - &info.sock, - mio::Token(token + DELTA), - mio::Ready::readable(), - mio::PollOpt::edge(), - ) { + if let Err(err) = self.register(token, info) { error!("Can not resume socket accept process: {}", err); } else { info!("Accepting connections on {} has been resumed", info.addr);