29 import java.util.concurrent.RejectedExecutionException; |
29 import java.util.concurrent.RejectedExecutionException; |
30 import java.io.IOException; |
30 import java.io.IOException; |
31 import sun.misc.Unsafe; |
31 import sun.misc.Unsafe; |
32 |
32 |
33 /** |
33 /** |
34 * AsynchronousChannelGroup implementation based on the Solaris 10 event port |
34 * Provides an AsynchronousChannelGroup implementation based on the Solaris 10 |
35 * framework. |
35 * event port framework and also provides direct access to that framework. |
36 */ |
36 */ |
37 |
37 |
38 class SolarisEventPort |
38 class SolarisEventPort |
39 extends Port |
39 extends Port |
40 { |
40 { |
52 * ushort_t portev_pad; |
52 * ushort_t portev_pad; |
53 * uintptr_t portev_object; |
53 * uintptr_t portev_object; |
54 * void *portev_user; |
54 * void *portev_user; |
55 * } port_event_t; |
55 * } port_event_t; |
56 */ |
56 */ |
57 private static final int SIZEOF_PORT_EVENT = dependsArch(16, 24); |
57 static final int SIZEOF_PORT_EVENT = dependsArch(16, 24); |
58 private static final int OFFSETOF_EVENTS = 0; |
58 static final int OFFSETOF_EVENTS = 0; |
59 private static final int OFFSETOF_SOURCE = 4; |
59 static final int OFFSETOF_SOURCE = 4; |
60 private static final int OFFSETOF_OBJECT = 8; |
60 static final int OFFSETOF_OBJECT = 8; |
61 |
61 |
62 // port sources |
62 // port sources |
63 private static final short PORT_SOURCE_USER = 3; |
63 static final short PORT_SOURCE_USER = 3; |
64 private static final short PORT_SOURCE_FD = 4; |
64 static final short PORT_SOURCE_FD = 4; |
65 |
65 |
66 // file descriptor to event port. |
66 // file descriptor to event port. |
67 private final int port; |
67 private final int port; |
68 |
68 |
69 // true when port is closed |
69 // true when port is closed |
135 @Override |
135 @Override |
136 void startPoll(int fd, int events) { |
136 void startPoll(int fd, int events) { |
137 // (re-)associate file descriptor |
137 // (re-)associate file descriptor |
138 // no need to translate events |
138 // no need to translate events |
139 try { |
139 try { |
140 portAssociate(port, PORT_SOURCE_FD, fd, events); |
140 port_associate(port, PORT_SOURCE_FD, fd, events); |
141 } catch (IOException x) { |
141 } catch (IOException x) { |
142 throw new AssertionError(); // should not happen |
142 throw new AssertionError(); // should not happen |
143 } |
143 } |
144 } |
144 } |
145 |
145 |
218 implClose(); |
218 implClose(); |
219 } |
219 } |
220 } |
220 } |
221 } |
221 } |
222 |
222 |
223 // -- Native methods -- |
223 /** |
224 |
224 * Creates an event port |
225 private static native void init(); |
225 */ |
226 |
226 static native int port_create() throws IOException; |
227 private static native int portCreate() throws IOException; |
227 |
228 |
228 /** |
229 private static native void portAssociate(int port, int source, long object, |
229 * Associates specific events of a given object with a port |
230 int events) throws IOException; |
230 */ |
231 |
231 static native boolean port_associate(int port, int source, long object, int events) |
232 private static native void portGet(int port, long pe) throws IOException; |
|
233 |
|
234 private static native int portGetn(int port, long address, int max) |
|
235 throws IOException; |
232 throws IOException; |
236 |
233 |
237 private static native void portSend(int port, int events) throws IOException; |
234 /** |
238 |
235 * Removes the association of an object with a port. |
239 private static native void portClose(int port); |
236 */ |
|
237 static native boolean port_dissociate(int port, int source, long object) |
|
238 throws IOException; |
|
239 |
|
240 /** |
|
241 * Retrieves a single event from a port |
|
242 */ |
|
243 static native void port_get(int port, long pe) throws IOException; |
|
244 |
|
245 /** |
|
246 * Retrieves at most {@code max} events from a port. |
|
247 */ |
|
248 static native int port_getn(int port, long address, int max, long timeout) |
|
249 throws IOException; |
|
250 |
|
251 /** |
|
252 * Sends a user-defined eventto a specified port. |
|
253 */ |
|
254 static native void port_send(int port, int events) throws IOException; |
|
255 |
|
256 /** |
|
257 * Closes a port. |
|
258 */ |
|
259 static native void port_close(int port); |
|
260 |
240 |
261 |
241 static { |
262 static { |
242 Util.load(); |
263 Util.load(); |
243 init(); |
|
244 } |
264 } |
245 } |
265 } |