Skip to content

Commit

Permalink
Kernel: Fix poll() with timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
rburchell authored and awesomekling committed May 18, 2019
1 parent b33cc7f commit 123283d
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions Kernel/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1854,9 +1854,27 @@ int Process::sys$poll(pollfd* fds, int nfds, int timeout)
current->m_select_write_fds.append(fds[i].fd);
}

// FIXME: this should set m_select_timeout, right?
if (timeout < 0)
if (timeout >= 0) {
// poll is in ms, we want s/us.
struct timeval tvtimeout;
tvtimeout.tv_sec = 0;
while (timeout >= 1000) {
tvtimeout.tv_sec += 1;
timeout -= 1000;
}
tvtimeout.tv_usec = timeout * 1000;

struct timeval now;
kgettimeofday(now);
AK::timeval_add(&now, &tvtimeout, &current->m_select_timeout);
current->m_select_has_timeout = true;
} else {
current->m_select_has_timeout = false;
}

if (current->m_select_has_timeout || timeout < 0) {
current->block(Thread::State::BlockedSelect);
}

int fds_with_revents = 0;

Expand Down

0 comments on commit 123283d

Please sign in to comment.