Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/unix/linux_like/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1847,21 +1847,26 @@ f! {
pub unsafe fn FD_CLR(fd: c_int, set: *mut fd_set) -> () {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please update these functions everywhere they exist? They exist in a lot of modules, not just Linux.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I'll take a look at it in the next few days.

let fd = fd as usize;
let size = size_of_val(&(*set).fds_bits[0]) * 8;
(*set).fds_bits[fd / size] &= !(1 << (fd % size));
return;
*(*set).fds_bits.get_mut(fd / size).unwrap_or_else(|| {
core::panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add panic! to the prelude (update the macro_rules! prelude)

}) &= !(1 << (fd % size));
Comment on lines -1850 to +1852

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is tough to read, use let Some(...) = ... else { ... } instead

}

pub unsafe fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool {
let fd = fd as usize;
let size = size_of_val(&(*set).fds_bits[0]) * 8;
return ((*set).fds_bits[fd / size] & (1 << (fd % size))) != 0;
(*set).fds_bits.get(fd / size).unwrap_or_else(|| {
core::panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})")
}) & (1 << (fd % size))
!= 0
}

pub unsafe fn FD_SET(fd: c_int, set: *mut fd_set) -> () {
let fd = fd as usize;
let size = size_of_val(&(*set).fds_bits[0]) * 8;
(*set).fds_bits[fd / size] |= 1 << (fd % size);
return;
*(*set).fds_bits.get_mut(fd / size).unwrap_or_else(|| {
core::panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})")
}) |= 1 << (fd % size);
}

pub unsafe fn FD_ZERO(set: *mut fd_set) -> () {
Expand Down
Loading