@@ -979,7 +979,7 @@ void _event_add_read_write(const struct xref_eventsched *xref,
979
979
* if we already have a pollfd for our file descriptor, find and
980
980
* use it
981
981
*/
982
- for (nfds_t i = 0 ; i < m -> handler .pfdcount ; i ++ )
982
+ for (nfds_t i = 0 ; i < m -> handler .pfdcount ; i ++ ) {
983
983
if (m -> handler .pfds [i ].fd == fd ) {
984
984
queuepos = i ;
985
985
@@ -993,6 +993,15 @@ void _event_add_read_write(const struct xref_eventsched *xref,
993
993
#endif
994
994
break ;
995
995
}
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
+ }
996
1005
997
1006
/* make sure we have room for this fd + pipe poker fd */
998
1007
assert (queuepos + 1 < m -> handler .pfdsize );
@@ -1269,6 +1278,14 @@ static void cancel_arg_helper(struct event_loop *master,
1269
1278
for (i = 0 ; i < master -> handler .pfdcount ;) {
1270
1279
pfd = master -> handler .pfds + i ;
1271
1280
1281
+ /*
1282
+ * Skip this spot, nothing here to see
1283
+ */
1284
+ if (pfd -> fd == -1 ) {
1285
+ i ++ ;
1286
+ continue ;
1287
+ }
1288
+
1272
1289
if (pfd -> events & POLLIN )
1273
1290
t = master -> read [pfd -> fd ];
1274
1291
else
@@ -1590,6 +1607,12 @@ static int thread_process_io_helper(struct event_loop *m, struct event *thread,
1590
1607
* we should.
1591
1608
*/
1592
1609
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 ;
1593
1616
1594
1617
if (!thread ) {
1595
1618
if ((actual_state & (POLLHUP |POLLIN )) != POLLHUP )
0 commit comments