Skip to content

Commit

Permalink
Properly compute the first parameter to the select(2) system call.
Browse files Browse the repository at this point in the history
  • Loading branch information
gijsbers committed Jun 28, 2024
1 parent c9ac56b commit 5c00dfc
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/yapp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,23 @@ int YApplication::mainLoop() {

for (fExitLoop = fExitApp; (fExitApp | fExitLoop) == false; ) {
bool didIdle = handleIdle();

int nfds = 0;
fd_set read_fds;
FD_ZERO(&read_fds);
fd_set write_fds;
FD_ZERO(&write_fds);

for (YPollIterType iPoll = polls.iterator(); ++iPoll; ) {
PRECONDITION(iPoll->fd() >= 0);
const int fd = iPoll->fd();
PRECONDITION(fd >= 0);
if (iPoll->forRead()) {
FD_SET(iPoll->fd(), &read_fds);
FD_SET(fd, &read_fds);
}
if (iPoll->forWrite()) {
FD_SET(iPoll->fd(), &write_fds);
FD_SET(fd, &write_fds);
}
if (nfds <= fd)
nfds = fd + 1;
}

timeval timeout = {0, 0L};
Expand All @@ -266,7 +269,7 @@ int YApplication::mainLoop() {
#endif

int rc;
rc = select(sizeof(fd_set) * 8,
rc = select(nfds,
SELECT_TYPE_ARG234 &read_fds,
SELECT_TYPE_ARG234 &write_fds,
nullptr,
Expand Down

0 comments on commit 5c00dfc

Please sign in to comment.