1 /* |
|
2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 */ |
|
25 |
|
26 package sun.nio.ch; |
|
27 |
|
28 |
|
29 /** |
|
30 * Manipulates a native array of pollfd structs. |
|
31 * |
|
32 * @author Mike McCloskey |
|
33 * @since 1.4 |
|
34 */ |
|
35 |
|
36 public abstract class AbstractPollArrayWrapper { |
|
37 |
|
38 // Miscellaneous constants |
|
39 static final short SIZE_POLLFD = 8; |
|
40 static final short FD_OFFSET = 0; |
|
41 static final short EVENT_OFFSET = 4; |
|
42 static final short REVENT_OFFSET = 6; |
|
43 |
|
44 // The poll fd array |
|
45 protected AllocatedNativeObject pollArray; |
|
46 |
|
47 // Number of valid entries in the pollArray |
|
48 protected int totalChannels = 0; |
|
49 |
|
50 // Base address of the native pollArray |
|
51 protected long pollArrayAddress; |
|
52 |
|
53 // Access methods for fd structures |
|
54 int getEventOps(int i) { |
|
55 int offset = SIZE_POLLFD * i + EVENT_OFFSET; |
|
56 return pollArray.getShort(offset); |
|
57 } |
|
58 |
|
59 int getReventOps(int i) { |
|
60 int offset = SIZE_POLLFD * i + REVENT_OFFSET; |
|
61 return pollArray.getShort(offset); |
|
62 } |
|
63 |
|
64 int getDescriptor(int i) { |
|
65 int offset = SIZE_POLLFD * i + FD_OFFSET; |
|
66 return pollArray.getInt(offset); |
|
67 } |
|
68 |
|
69 void putEventOps(int i, int event) { |
|
70 int offset = SIZE_POLLFD * i + EVENT_OFFSET; |
|
71 pollArray.putShort(offset, (short)event); |
|
72 } |
|
73 |
|
74 void putReventOps(int i, int revent) { |
|
75 int offset = SIZE_POLLFD * i + REVENT_OFFSET; |
|
76 pollArray.putShort(offset, (short)revent); |
|
77 } |
|
78 |
|
79 void putDescriptor(int i, int fd) { |
|
80 int offset = SIZE_POLLFD * i + FD_OFFSET; |
|
81 pollArray.putInt(offset, fd); |
|
82 } |
|
83 |
|
84 } |
|