/[classpath]/classpath/gnu/java/nio/SelectorImpl.java
ViewVC logotype

Diff of /classpath/gnu/java/nio/SelectorImpl.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by mkoch, Thu Sep 25 14:01:17 2003 UTC revision 1.9 by mkoch, Thu Sep 25 17:50:35 2003 UTC
# Line 80  public class SelectorImpl extends Abstra Line 80  public class SelectorImpl extends Abstra
80      return Collections.unmodifiableSet (keys);      return Collections.unmodifiableSet (keys);
81    }    }
82            
83    public int selectNow ()    public final int selectNow()
84        throws IOException
85    {    {
86      return select (1);      return select (1);
87    }    }
88    
89    public int select ()    public final int select()
90        throws IOException
91    {    {
92      return select (-1);      return select (-1);
93    }    }
94    
95    // A timeout value of -1 means block forever.    // A timeout value of -1 means block forever.
96    private static native int java_do_select (int[] read, int[] write,    private static native int implSelect (int[] read, int[] write,
97                                              int[] except, long timeout);                                          int[] except, long timeout);
98    
99    private int[] getFDsAsArray (int ops)    private final int[] getFDsAsArray (int ops)
100    {    {
101      int[] result;      int[] result;
102      int counter = 0;      int counter = 0;
# Line 141  public class SelectorImpl extends Abstra Line 143  public class SelectorImpl extends Abstra
143          return 0;          return 0;
144              }              }
145    
     int ret = 0;  
   
146      deregisterCancelledKeys();      deregisterCancelledKeys();
147    
148      // Set only keys with the needed interest ops into the arrays.      // Set only keys with the needed interest ops into the arrays.
149      int[] read = getFDsAsArray (SelectionKey.OP_READ | SelectionKey.OP_ACCEPT);      int[] read = getFDsAsArray (SelectionKey.OP_READ | SelectionKey.OP_ACCEPT);
150      int[] write = getFDsAsArray (SelectionKey.OP_WRITE | SelectionKey.OP_CONNECT);      int[] write = getFDsAsArray (SelectionKey.OP_WRITE | SelectionKey.OP_CONNECT);
151      int[] except = new int [0]; // FIXME: We dont need to check this yet      int[] except = new int [0]; // FIXME: We dont need to check this yet
   
     // Call the native select () on all file descriptors.  
152      int anzahl = read.length + write.length + except.length;      int anzahl = read.length + write.length + except.length;
153      ret = java_do_select (read, write, except, timeout);  
154        // Call the native select() on all file descriptors.
155        begin();
156        int result = implSelect (read, write, except, timeout);
157        end();
158    
159      Iterator it = keys.iterator ();      Iterator it = keys.iterator ();
160    
# Line 206  public class SelectorImpl extends Abstra Line 208  public class SelectorImpl extends Abstra
208          // If key is not yet selected add it.          // If key is not yet selected add it.
209          if (!selected.contains (key))          if (!selected.contains (key))
210            {            {
211              add_selected (key);              selected.add (key);
212            }            }
213    
214          // Set new ready ops          // Set new ready ops
# Line 214  public class SelectorImpl extends Abstra Line 216  public class SelectorImpl extends Abstra
216        }        }
217    
218      deregisterCancelledKeys();      deregisterCancelledKeys();
219      return ret;      return result;
220    }    }
221            
222    public Set selectedKeys ()    public final Set selectedKeys()
223    {    {
224      return selected;      return selected;
225    }    }
226    
227    public Selector wakeup ()    public final Selector wakeup()
228    {    {
229      return null;      return null;
230    }    }
231    
232    public void add (SelectionKeyImpl k)    private final void deregisterCancelledKeys()
   {  
     keys.add (k);  
   }  
   
   void add_selected (SelectionKeyImpl k)  
   {  
     selected.add (k);  
   }  
   
   private void deregisterCancelledKeys ()  
233    {    {
234      Iterator it = cancelledKeys().iterator();      Iterator it = cancelledKeys().iterator();
235    
# Line 253  public class SelectorImpl extends Abstra Line 245  public class SelectorImpl extends Abstra
245      return register ((AbstractSelectableChannel) ch, ops, att);      return register ((AbstractSelectableChannel) ch, ops, att);
246    }    }
247    
248    protected SelectionKey register (AbstractSelectableChannel ch, int ops,    protected final SelectionKey register (AbstractSelectableChannel ch, int ops,
249                                     Object att)                                           Object att)
250    {    {
251      SelectionKeyImpl result;      SelectionKeyImpl result;
252            
# Line 278  public class SelectorImpl extends Abstra Line 270  public class SelectorImpl extends Abstra
270          throw new InternalError ("No known channel type");          throw new InternalError ("No known channel type");
271        }        }
272    
273      add (result);      keys.add (result);
274      result.interestOps (ops);      result.interestOps (ops);
275      result.attach (att);      result.attach (att);
276      return result;      return result;

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26