/** Translates native poll revent set into a ready operation set */
  public boolean translateReadyOps(int ops, int initialOps, SelectionKeyImpl sk) {
    int intOps = sk.nioInterestOps(); // Do this just once, it synchronizes
    int oldOps = sk.nioReadyOps();
    int newOps = initialOps;

    if ((ops & Net.POLLNVAL) != 0) {
      // This should only happen if this channel is pre-closed while a
      // selection operation is in progress
      // ## Throw an error if this channel has not been pre-closed
      return false;
    }

    if ((ops & (Net.POLLERR | Net.POLLHUP)) != 0) {
      newOps = intOps;
      sk.nioReadyOps(newOps);
      return (newOps & ~oldOps) != 0;
    }

    if (((ops & Net.POLLIN) != 0) && ((intOps & SelectionKey.OP_READ) != 0))
      newOps |= SelectionKey.OP_READ;

    if (((ops & Net.POLLOUT) != 0) && ((intOps & SelectionKey.OP_WRITE) != 0))
      newOps |= SelectionKey.OP_WRITE;

    sk.nioReadyOps(newOps);
    return (newOps & ~oldOps) != 0;
  }
  public boolean translateReadyOps(int ops, int initialOps, SelectionKeyImpl sk) {
    int intOps = sk.nioInterestOps(); // Do this just once, it synchronizes
    int oldOps = sk.nioReadyOps();
    int newOps = initialOps;

    if ((ops & PollArrayWrapper.POLLNVAL) != 0) throw new Error("POLLNVAL detected");

    if ((ops & (PollArrayWrapper.POLLERR | PollArrayWrapper.POLLHUP)) != 0) {
      newOps = intOps;
      sk.nioReadyOps(newOps);
      return (newOps & ~oldOps) != 0;
    }

    if (((ops & PollArrayWrapper.POLLIN) != 0) && ((intOps & SelectionKey.OP_READ) != 0))
      newOps |= SelectionKey.OP_READ;

    sk.nioReadyOps(newOps);
    return (newOps & ~oldOps) != 0;
  }
  /** Translates native poll revent ops into a ready operation ops */
  public boolean translateReadyOps(int ops, int initialOps, SelectionKeyImpl sk) {
    int intOps = sk.nioInterestOps(); // Do this just once, it synchronizes
    int oldOps = sk.nioReadyOps();
    int newOps = initialOps;

    if ((ops & PollArrayWrapper.POLLNVAL) != 0) {
      // This should only happen if this channel is pre-closed while a
      // selection operation is in progress
      // ## Throw an error if this channel has not been pre-closed
      return false;
    }

    if ((ops & (PollArrayWrapper.POLLERR | PollArrayWrapper.POLLHUP)) != 0) {
      newOps = intOps;
      sk.nioReadyOps(newOps);
      // No need to poll again in checkConnect,
      // the error will be detected there
      readyToConnect = true;
      return (newOps & ~oldOps) != 0;
    }

    if (((ops & PollArrayWrapper.POLLIN) != 0)
        && ((intOps & SelectionKey.OP_READ) != 0)
        && (state == ST_CONNECTED)) newOps |= SelectionKey.OP_READ;

    if (((ops & PollArrayWrapper.POLLCONN) != 0)
        && ((intOps & SelectionKey.OP_CONNECT) != 0)
        && ((state == ST_UNCONNECTED) || (state == ST_PENDING))) {
      newOps |= SelectionKey.OP_CONNECT;
      readyToConnect = true;
    }

    if (((ops & PollArrayWrapper.POLLOUT) != 0)
        && ((intOps & SelectionKey.OP_WRITE) != 0)
        && (state == ST_CONNECTED)) newOps |= SelectionKey.OP_WRITE;

    sk.nioReadyOps(newOps);
    return (newOps & ~oldOps) != 0;
  }
 public boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl sk) {
   return translateReadyOps(ops, sk.nioReadyOps(), sk);
 }