Skip to content

Commit

Permalink
Fix wrong handling of MAX_REGISTRATIONS
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Aug 9, 2024
1 parent 73a020f commit 6378246
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/reactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ use crate::{syscall, syscall_los, syscall_los_eagain};
// For ESP-IDF sys::FDSETSIZE is currently wrongly set to 1024 in the `libc` crate
// Therefore, use a custom value for now
#[cfg(target_os = "espidf")]
const MAX_REGISTRATIONS: usize = 20;
const MAX_FDS: usize = 64;

#[cfg(not(target_os = "espidf"))]
const MAX_REGISTRATIONS: usize = sys::FD_SETSIZE;
const MAX_FDS: usize = sys::FD_SETSIZE;

// In future, we might want to use a smaller - and possibly - configurable - with cargo feature(s)
// amount of registrations to save memory, but for now, let's use the maximum amount
const MAX_REGISTRATIONS: usize = MAX_FDS;

#[derive(EnumSetType, Debug)]
pub(crate) enum Event {
Expand Down Expand Up @@ -110,8 +114,8 @@ impl<const N: usize> Registrations<N> {
Err(ErrorKind::InvalidInput)?;
}

if fd >= sys::FD_SETSIZE as RawFd || fd >= N as RawFd {
Err(ErrorKind::OutOfMemory)?;
if fd >= MAX_FDS as RawFd {
Err(ErrorKind::InvalidInput)?;
}

if self.vec.iter().any(|reg| reg.fd == fd) {
Expand Down

0 comments on commit 6378246

Please sign in to comment.