Skip to content

Commit 6378246

Browse files
committed
Fix wrong handling of MAX_REGISTRATIONS
1 parent 73a020f commit 6378246

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/reactor.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ use crate::{syscall, syscall_los, syscall_los_eagain};
1717
// For ESP-IDF sys::FDSETSIZE is currently wrongly set to 1024 in the `libc` crate
1818
// Therefore, use a custom value for now
1919
#[cfg(target_os = "espidf")]
20-
const MAX_REGISTRATIONS: usize = 20;
20+
const MAX_FDS: usize = 64;
2121

2222
#[cfg(not(target_os = "espidf"))]
23-
const MAX_REGISTRATIONS: usize = sys::FD_SETSIZE;
23+
const MAX_FDS: usize = sys::FD_SETSIZE;
24+
25+
// In future, we might want to use a smaller - and possibly - configurable - with cargo feature(s)
26+
// amount of registrations to save memory, but for now, let's use the maximum amount
27+
const MAX_REGISTRATIONS: usize = MAX_FDS;
2428

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

113-
if fd >= sys::FD_SETSIZE as RawFd || fd >= N as RawFd {
114-
Err(ErrorKind::OutOfMemory)?;
117+
if fd >= MAX_FDS as RawFd {
118+
Err(ErrorKind::InvalidInput)?;
115119
}
116120

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

0 commit comments

Comments
 (0)