- int offs = fd >> 3;
- int mask = 1 << (fd & 7);
-
- if (vec_max < (fd >> 5) + 1)
- {
- vec_max = (fd >> 5) + 1;
-
- vec_ri = (unsigned char *)realloc (vec_ri, vec_max * 4);
- vec_ro = (unsigned char *)realloc (vec_ro, vec_max * 4); /* could free/malloc */
- vec_wi = (unsigned char *)realloc (vec_wi, vec_max * 4);
- vec_wo = (unsigned char *)realloc (vec_wo, vec_max * 4); /* could free/malloc */
- }
-
- vec_ri [offs] |= mask;
- if (!(nev & EV_READ))
- vec_ri [offs] &= ~mask;
-
- vec_wi [offs] |= mask;
- if (!(nev & EV_WRITE))
- vec_wi [offs] &= ~mask;
+ if (oev == nev)
+ return;
+
+ {
+#if EV_SELECT_USE_FD_SET
+
+ #if EV_SELECT_IS_WINSOCKET
+ SOCKET handle = anfds [fd].handle;
+ #else
+ int handle = fd;
+ #endif
+
+ if (nev & EV_READ)
+ FD_SET (handle, (fd_set *)vec_ri);
+ else
+ FD_CLR (handle, (fd_set *)vec_ri);
+
+ if (nev & EV_WRITE)
+ FD_SET (handle, (fd_set *)vec_wi);
+ else
+ FD_CLR (handle, (fd_set *)vec_wi);
+
+#else
+
+ int word = fd / NFDBITS;
+ int mask = 1UL << (fd % NFDBITS);
+
+ if (expect_false (vec_max < word + 1))
+ {
+ int new_max = word + 1;
+
+ vec_ri = ev_realloc (vec_ri, new_max * NFDBYTES);
+ vec_ro = ev_realloc (vec_ro, new_max * NFDBYTES); /* could free/malloc */
+ vec_wi = ev_realloc (vec_wi, new_max * NFDBYTES);
+ vec_wo = ev_realloc (vec_wo, new_max * NFDBYTES); /* could free/malloc */
+
+ for (; vec_max < new_max; ++vec_max)
+ ((fd_mask *)vec_ri)[vec_max] =
+ ((fd_mask *)vec_wi)[vec_max] = 0;
+ }
+
+ ((fd_mask *)vec_ri) [word] |= mask;
+ if (!(nev & EV_READ))
+ ((fd_mask *)vec_ri) [word] &= ~mask;
+
+ ((fd_mask *)vec_wi) [word] |= mask;
+ if (!(nev & EV_WRITE))
+ ((fd_mask *)vec_wi) [word] &= ~mask;
+#endif
+ }