Avoid error by `register()` on Windows
@@ -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);
