int getDescriptor(int index) {
   int offset = SIZEOF_KEVENT * index + FD_OFFSET;
   /* The ident field is 8 bytes in 64-bit world, however the API wants us
    * to return an int. Hence read the 8 bytes but return as an int.
    */
   if (is64bit) {
     long fd = keventArray.getLong(offset);
     assert fd <= Integer.MAX_VALUE;
     return (int) fd;
   } else {
     return keventArray.getInt(offset);
   }
 }
  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);
      }
    }
  }
 void close() throws IOException {
   if (keventArray != null) {
     keventArray.free();
     keventArray = null;
   }
   if (kq >= 0) {
     FileDispatcherImpl.closeIntFD(kq);
     kq = -1;
   }
 }
  int getReventOps(int index) {
    int result = 0;
    int offset = SIZEOF_KEVENT * index + FILTER_OFFSET;
    short filter = keventArray.getShort(offset);

    // This is all that's necessary based on inspection of usage:
    //   SinkChannelImpl, SourceChannelImpl, DatagramChannelImpl,
    //   ServerSocketChannelImpl, SocketChannelImpl
    if (filter == EVFILT_READ) {
      result |= POLLIN;
    } else if (filter == EVFILT_WRITE) {
      result |= POLLOUT;
    }

    return result;
  }
 private void putPollFD(AllocatedNativeObject array, int index, int fd, short event) {
   int structIndex = SIZE_POLLFD * index;
   array.putInt(structIndex + FD_OFFSET, fd);
   array.putShort(structIndex + EVENT_OFFSET, event);
   array.putShort(structIndex + REVENT_OFFSET, (short) 0);
 }
 void closeDevPollFD() throws IOException {
   FileDispatcherImpl.closeIntFD(wfd);
   pollArray.free();
   updatePollArray.free();
 }
 int getDescriptor(int i) {
   int offset = SIZE_POLLFD * i + FD_OFFSET;
   return pollArray.getInt(offset);
 }
 int getReventOps(int i) {
   int offset = SIZE_POLLFD * i + REVENT_OFFSET;
   return pollArray.getShort(offset);
 }
 void putReventOps(int i, int revent) {
   int offset = SIZE_POLLFD * i + REVENT_OFFSET;
   pollArray.putShort(offset, (short) revent);
 }
Esempio n. 10
0
 KQueueArrayWrapper() {
   int allocationSize = SIZEOF_KEVENT * NUM_KEVENTS;
   keventArray = new AllocatedNativeObject(allocationSize, true);
   keventArrayAddress = keventArray.address();
   kq = init();
 }