void updateRegistrations() throws IOException { // Populate pollfd array with updated masks synchronized (updateList) { while (updateList.size() > 0) { // We have to insert a dummy node in between each // real update to use POLLREMOVE on the fd first because // otherwise the changes are simply OR'd together int index = 0; Updator u = null; while ((u = updateList.poll()) != null) { // First add pollfd struct to clear out this fd putPollFD(updatePollArray, index, u.fd, POLLREMOVE); index++; // Now add pollfd to update this fd, if necessary if (u.mask != POLLREMOVE) { putPollFD(updatePollArray, index, u.fd, (short) u.mask); index++; } // Check against the max update size; these are // all we will process. Valid index ranges from 0 to // (MAX_UPDATE_SIZE - 1) and we can use up to 2 per loop if (index > MAX_UPDATE_SIZE - 2) break; } // Register the changes with /dev/poll registerMultiple(wfd, updatePollArray.address(), index); } } }
KQueueArrayWrapper() { int allocationSize = SIZEOF_KEVENT * NUM_KEVENTS; keventArray = new AllocatedNativeObject(allocationSize, true); keventArrayAddress = keventArray.address(); kq = init(); }