1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-27 16:52:58 +01:00

Avoid error by register() on Windows (#103)

This commit is contained in:
Dany Laporte 2020-02-26 04:40:31 -05:00 committed by GitHub
parent c69bc11e3e
commit 83320efa31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -298,12 +298,7 @@ impl Accept {
} }
Command::Resume => { Command::Resume => {
for (token, info) in self.sockets.iter() { for (token, info) in self.sockets.iter() {
if let Err(err) = self.poll.register( if let Err(err) = self.register(token, info) {
&info.sock,
mio::Token(token + DELTA),
mio::Ready::readable(),
mio::PollOpt::edge(),
) {
error!("Can not resume socket accept process: {}", err); error!("Can not resume socket accept process: {}", err);
} else { } else {
info!( info!(
@ -338,17 +333,44 @@ impl Accept {
true 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) { fn backpressure(&mut self, on: bool) {
if self.backpressure { if self.backpressure {
if !on { if !on {
self.backpressure = false; self.backpressure = false;
for (token, info) in self.sockets.iter() { for (token, info) in self.sockets.iter() {
if let Err(err) = self.poll.register( if let Err(err) = self.register(token, info) {
&info.sock,
mio::Token(token + DELTA),
mio::Ready::readable(),
mio::PollOpt::edge(),
) {
error!("Can not resume socket accept process: {}", err); error!("Can not resume socket accept process: {}", err);
} else { } else {
info!("Accepting connections on {} has been resumed", info.addr); info!("Accepting connections on {} has been resumed", info.addr);