Skip to content

Commit

Permalink
refactor(PollEvent): collapse if statements
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening authored and stlankes committed Feb 16, 2024
1 parent 7b672ef commit 0da021f
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions src/fd/socket/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ impl ObjectInterface for Socket {
Poll::Pending
}
_ => {
if socket.may_recv() && self.listen.swap(false, Ordering::Relaxed) {
if socket.can_recv()
|| socket.may_recv() && self.listen.swap(false, Ordering::Relaxed)
{
// In case, we just establish a fresh connection in non-blocking mode, we try to read data.
if event.contains(PollEvent::POLLIN) {
ret.insert(PollEvent::POLLIN);
Expand All @@ -233,18 +235,6 @@ impl ObjectInterface for Socket {
}
}

if socket.can_recv() {
if event.contains(PollEvent::POLLIN) {
ret.insert(PollEvent::POLLIN);
}
if event.contains(PollEvent::POLLRDNORM) {
ret.insert(PollEvent::POLLRDNORM);
}
if event.contains(PollEvent::POLLRDBAND) {
ret.insert(PollEvent::POLLRDBAND);
}
}

if ret.is_empty() {
socket.register_recv_waker(cx.waker());
socket.register_send_waker(cx.waker());
Expand Down

0 comments on commit 0da021f

Please sign in to comment.