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 committed Feb 15, 2024
1 parent d6ad4ee commit f46b988
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 f46b988

Please sign in to comment.