Skip to content

Commit

Permalink
fix Interest operation
Browse files Browse the repository at this point in the history
  • Loading branch information
lazytiger committed May 26, 2021
1 parent 3621cfd commit 44f671c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
14 changes: 10 additions & 4 deletions src/proxy/tcp_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,19 +257,25 @@ impl Connection {
_ => {
let mut changed = false;
if !self.send_buffer.is_empty() && !self.client_readiness.is_writable() {
self.client_readiness.add(Interest::WRITABLE);
self.client_readiness |= Interest::WRITABLE;
changed = true;
}
if self.send_buffer.is_empty() && self.client_readiness.is_writable() {
self.client_readiness.remove(Interest::WRITABLE);
self.client_readiness = self
.client_readiness
.remove(Interest::WRITABLE)
.unwrap_or(Interest::READABLE);
changed = true;
}
if self.server_conn.writable() && !self.client_readiness.is_readable() {
self.client_readiness.add(Interest::READABLE);
self.client_readiness |= Interest::READABLE;
changed = true;
}
if !self.server_conn.writable() && self.client_readiness.is_readable() {
self.client_readiness.remove(Interest::READABLE);
self.client_readiness = self
.client_readiness
.remove(Interest::READABLE)
.unwrap_or(Interest::WRITABLE);
changed = true;
}

Expand Down
14 changes: 10 additions & 4 deletions src/server/tcp_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,28 @@ impl Backend for TcpBackend {
_ => {
let mut changed = false;
if !self.send_buffer.is_empty() && !self.readiness.is_writable() {
self.readiness.add(Interest::WRITABLE);
self.readiness |= Interest::WRITABLE;
changed = true;
log::debug!("connection:{} add writable to tcp target", self.index);
}
if self.send_buffer.is_empty() && self.readiness.is_writable() {
self.readiness.remove(Interest::WRITABLE);
self.readiness = self
.readiness
.remove(Interest::WRITABLE)
.unwrap_or(Interest::READABLE);
changed = true;
log::debug!("connection:{} remove writable from tcp target", self.index);
}
if readable && !self.readiness.is_readable() {
self.readiness.add(Interest::READABLE);
self.readiness |= Interest::READABLE;
log::debug!("connection:{} add readable to tcp target", self.index);
changed = true;
}
if !readable && self.readiness.is_readable() {
self.readiness.remove(Interest::READABLE);
self.readiness = self
.readiness
.remove(Interest::READABLE)
.unwrap_or(Interest::WRITABLE);
log::debug!("connection:{} remove readable from tcp target", self.index);
changed = true;
}
Expand Down
14 changes: 10 additions & 4 deletions src/server/udp_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,28 @@ impl Backend for UdpBackend {
_ => {
let mut changed = false;
if !self.send_buffer.is_empty() && !self.readiness.is_writable() {
self.readiness.add(Interest::WRITABLE);
self.readiness |= Interest::WRITABLE;
changed = true;
log::debug!("connection:{} add writable to udp target", self.index);
}
if self.send_buffer.is_empty() && self.readiness.is_writable() {
self.readiness.remove(Interest::WRITABLE);
self.readiness = self
.readiness
.remove(Interest::WRITABLE)
.unwrap_or(Interest::READABLE);
changed = true;
log::debug!("connection:{} remove writable from udp target", self.index);
}
if readable && !self.readiness.is_readable() {
self.readiness.add(Interest::READABLE);
self.readiness |= Interest::READABLE;
log::debug!("connection:{} add readable to udp target", self.index);
changed = true;
}
if !readable && self.readiness.is_readable() {
self.readiness.remove(Interest::READABLE);
self.readiness = self
.readiness
.remove(Interest::READABLE)
.unwrap_or(Interest::WRITABLE);
log::debug!("connection:{} remove readable to udp target", self.index);
changed = true;
}
Expand Down
14 changes: 10 additions & 4 deletions src/tls_conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,26 @@ impl<T: Session> TlsConn<T> {
_ => {
let mut changed = false;
if self.session.wants_write() && !self.readiness.is_writable() {
self.readiness.add(Interest::WRITABLE);
self.readiness |= Interest::WRITABLE;
changed = true;
}
if !self.session.wants_write() && self.readiness.is_writable() {
self.readiness.remove(Interest::WRITABLE);
self.readiness = self
.readiness
.remove(Interest::WRITABLE)
.unwrap_or(Interest::READABLE);
changed = true;
}
if readable && !self.readiness.is_readable() {
self.readiness.add(Interest::READABLE);
self.readiness |= Interest::READABLE;
changed = true;
}

if !readable && self.readiness.is_readable() {
self.readiness.remove(Interest::READABLE);
self.readiness = self
.readiness
.remove(Interest::READABLE)
.unwrap_or(Interest::WRITABLE);
changed = true;
}
if changed {
Expand Down

0 comments on commit 44f671c

Please sign in to comment.