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; |
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 |
|
|
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 |
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 |
|
|
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 |
|
|
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; |