Skip to content

Commit 841f7a4

Browse files
authored
Merge pull request #17025 from donaldsharp/ppoll_fix
2 parents 3f69054 + d11ad98 commit 841f7a4

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

lib/event.c

+24-1
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ void _event_add_read_write(const struct xref_eventsched *xref,
979979
* if we already have a pollfd for our file descriptor, find and
980980
* use it
981981
*/
982-
for (nfds_t i = 0; i < m->handler.pfdcount; i++)
982+
for (nfds_t i = 0; i < m->handler.pfdcount; i++) {
983983
if (m->handler.pfds[i].fd == fd) {
984984
queuepos = i;
985985

@@ -993,6 +993,15 @@ void _event_add_read_write(const struct xref_eventsched *xref,
993993
#endif
994994
break;
995995
}
996+
/*
997+
* We are setting the fd = -1 for the
998+
* case when a read/write event is going
999+
* away. if we find a -1 we can stuff it
1000+
* into that spot, so note it
1001+
*/
1002+
if (m->handler.pfds[i].fd == -1 && queuepos == m->handler.pfdcount)
1003+
queuepos = i;
1004+
}
9961005

9971006
/* make sure we have room for this fd + pipe poker fd */
9981007
assert(queuepos + 1 < m->handler.pfdsize);
@@ -1269,6 +1278,14 @@ static void cancel_arg_helper(struct event_loop *master,
12691278
for (i = 0; i < master->handler.pfdcount;) {
12701279
pfd = master->handler.pfds + i;
12711280

1281+
/*
1282+
* Skip this spot, nothing here to see
1283+
*/
1284+
if (pfd->fd == -1) {
1285+
i++;
1286+
continue;
1287+
}
1288+
12721289
if (pfd->events & POLLIN)
12731290
t = master->read[pfd->fd];
12741291
else
@@ -1590,6 +1607,12 @@ static int thread_process_io_helper(struct event_loop *m, struct event *thread,
15901607
* we should.
15911608
*/
15921609
m->handler.pfds[pos].events &= ~(state);
1610+
/*
1611+
* ppoll man page says that a fd of -1 causes the particular
1612+
* array item to be skipped. So let's skip it
1613+
*/
1614+
if (m->handler.pfds[pos].events == 0)
1615+
m->handler.pfds[pos].fd = -1;
15931616

15941617
if (!thread) {
15951618
if ((actual_state & (POLLHUP|POLLIN)) != POLLHUP)

0 commit comments

Comments
 (0)