jdk/src/solaris/classes/sun/nio/ch/DevPollSelectorImpl.java
changeset 895 67f1dc69ad10
parent 2 90ce3da70b43
child 1247 b4c26443dee5
equal deleted inserted replaced
894:15e617238139 895:67f1dc69ad10
    48 
    48 
    49     // The number of valid channels in this Selector's poll array
    49     // The number of valid channels in this Selector's poll array
    50     private int totalChannels;
    50     private int totalChannels;
    51 
    51 
    52     // Maps from file descriptors to keys
    52     // Maps from file descriptors to keys
    53     private HashMap fdToKey;
    53     private Map<Integer,SelectionKeyImpl> fdToKey;
    54 
    54 
    55     // True if this Selector has been closed
    55     // True if this Selector has been closed
    56     private boolean closed = false;
    56     private boolean closed = false;
    57 
    57 
    58     // Lock for interrupt triggering and clearing
    58     // Lock for interrupt triggering and clearing
    69         IOUtil.initPipe(fdes, false);
    69         IOUtil.initPipe(fdes, false);
    70         fd0 = fdes[0];
    70         fd0 = fdes[0];
    71         fd1 = fdes[1];
    71         fd1 = fdes[1];
    72         pollWrapper = new DevPollArrayWrapper();
    72         pollWrapper = new DevPollArrayWrapper();
    73         pollWrapper.initInterrupt(fd0, fd1);
    73         pollWrapper.initInterrupt(fd0, fd1);
    74         fdToKey = new HashMap();
    74         fdToKey = new HashMap<Integer,SelectionKeyImpl>();
    75         totalChannels = 1;
    75         totalChannels = 1;
    76     }
    76     }
    77 
    77 
    78     protected int doSelect(long timeout)
    78     protected int doSelect(long timeout)
    79         throws IOException
    79         throws IOException
   108     private int updateSelectedKeys() {
   108     private int updateSelectedKeys() {
   109         int entries = pollWrapper.updated;
   109         int entries = pollWrapper.updated;
   110         int numKeysUpdated = 0;
   110         int numKeysUpdated = 0;
   111         for (int i=0; i<entries; i++) {
   111         for (int i=0; i<entries; i++) {
   112             int nextFD = pollWrapper.getDescriptor(i);
   112             int nextFD = pollWrapper.getDescriptor(i);
   113             SelectionKeyImpl ski = (SelectionKeyImpl) fdToKey.get(
   113             SelectionKeyImpl ski = fdToKey.get(Integer.valueOf(nextFD));
   114                 new Integer(nextFD));
       
   115             // ski is null in the case of an interrupt
   114             // ski is null in the case of an interrupt
   116             if (ski != null) {
   115             if (ski != null) {
   117                 int rOps = pollWrapper.getReventOps(i);
   116                 int rOps = pollWrapper.getReventOps(i);
   118                 if (selectedKeys.contains(ski)) {
   117                 if (selectedKeys.contains(ski)) {
   119                     if (ski.channel.translateAndSetReadyOps(rOps, ski)) {
   118                     if (ski.channel.translateAndSetReadyOps(rOps, ski)) {
   167         }
   166         }
   168     }
   167     }
   169 
   168 
   170     protected void implRegister(SelectionKeyImpl ski) {
   169     protected void implRegister(SelectionKeyImpl ski) {
   171         int fd = IOUtil.fdVal(ski.channel.getFD());
   170         int fd = IOUtil.fdVal(ski.channel.getFD());
   172         fdToKey.put(new Integer(fd), ski);
   171         fdToKey.put(Integer.valueOf(fd), ski);
   173         totalChannels++;
   172         totalChannels++;
   174         keys.add(ski);
   173         keys.add(ski);
   175     }
   174     }
   176 
   175 
   177     protected void implDereg(SelectionKeyImpl ski) throws IOException {
   176     protected void implDereg(SelectionKeyImpl ski) throws IOException {
   178         int i = ski.getIndex();
   177         int i = ski.getIndex();
   179         assert (i >= 0);
   178         assert (i >= 0);
   180         int fd = ski.channel.getFDVal();
   179         int fd = ski.channel.getFDVal();
   181         fdToKey.remove(new Integer(fd));
   180         fdToKey.remove(Integer.valueOf(fd));
   182         pollWrapper.release(fd);
   181         pollWrapper.release(fd);
   183         totalChannels--;
   182         totalChannels--;
   184         ski.setIndex(-1);
   183         ski.setIndex(-1);
   185         keys.remove(ski);
   184         keys.remove(ski);
   186         selectedKeys.remove(ski);
   185         selectedKeys.remove(ski);