Skip to content

Commit bf8121c

Browse files
fix(epoll): timeout
Signed-off-by: Anhad Singh <[email protected]>
1 parent adbe0ad commit bf8121c

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/aero_kernel/src/fs/epoll.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with Aero. If not, see <https://www.gnu.org/licenses/>.
1717

18+
// TODO: The reason why XFE did not run was because of the FXSleep function which uses select() to
19+
// sleep.
20+
1821
use aero_syscall::prelude::{EPollEvent, EPollEventFlags};
1922
use aero_syscall::SyscallError;
2023

@@ -170,7 +173,7 @@ impl EPoll {
170173
}
171174

172175
// If all events are ready, we can return now.
173-
if n > 0 {
176+
if n > 0 || fds.is_empty() {
174177
debug_assert!(fds.is_empty());
175178
return Ok(n);
176179
}
@@ -181,9 +184,22 @@ impl EPoll {
181184
return Ok(0);
182185
}
183186

187+
if timeout > 0 {
188+
scheduler::get_scheduler()
189+
.inner
190+
.sleep(Some(timeout * 1_000_000))?;
191+
} else {
192+
scheduler::get_scheduler().inner.sleep(None)?;
193+
}
194+
184195
'search: loop {
185196
scheduler::get_scheduler().inner.await_io()?;
186197

198+
if current_task.load_sleep_duration() == 0 && timeout > 0 {
199+
// Timeout has expired.
200+
return Ok(0);
201+
}
202+
187203
for (fd, event, flags) in fds.iter_mut() {
188204
// If the event mask does not contain any poll(2) events, the event
189205
// descriptor is disabled.

0 commit comments

Comments
 (0)