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 /* 27 */ 28 29 package sun.nio.ch; 30 31 /** 32 * Manipulates a native array of structs corresponding to (fd, events) pairs. 33 * 34 * typedef struct pollfd { 35 * SOCKET fd; // 4 bytes 36 * short events; // 2 bytes 37 * } pollfd_t; 38 * 39 * @author Konstantin Kladko 40 * @author Mike McCloskey 41 */ 42 43 class PollArrayWrapper { 44 45 private AllocatedNativeObject pollArray; // The fd array 46 47 long pollArrayAddress; // pollArrayAddress 48 49 private static final short FD_OFFSET = 0; // fd offset in pollfd 50 private static final short EVENT_OFFSET = 4; // events offset in pollfd 51 52 static short SIZE_POLLFD = 8; // sizeof pollfd struct 53 54 // events masks 55 static final short POLLIN = AbstractPollArrayWrapper.POLLIN; 56 static final short POLLOUT = AbstractPollArrayWrapper.POLLOUT; 57 static final short POLLERR = AbstractPollArrayWrapper.POLLERR; 58 static final short POLLHUP = AbstractPollArrayWrapper.POLLHUP; 59 static final short POLLNVAL = AbstractPollArrayWrapper.POLLNVAL; 60 static final short POLLREMOVE = AbstractPollArrayWrapper.POLLREMOVE; 61 static final short POLLCONN = 0x0002; 62 63 private int size; // Size of the pollArray 64 65 PollArrayWrapper(int newSize) { 66 int allocationSize = newSize * SIZE_POLLFD; 67 pollArray = new AllocatedNativeObject(allocationSize, true); 68 pollArrayAddress = pollArray.address(); 69 this.size = newSize; 70 } 71 72 // Prepare another pollfd struct for use. 73 void addEntry(int index, SelectionKeyImpl ski) { 74 putDescriptor(index, ski.channel.getFDVal()); 75 } 76 77 // Writes the pollfd entry from the source wrapper at the source index 78 // over the entry in the target wrapper at the target index. 79 void replaceEntry(PollArrayWrapper source, int sindex, 80 PollArrayWrapper target, int tindex) { 81 target.putDescriptor(tindex, source.getDescriptor(sindex)); | 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 /* 27 */ 28 29 package sun.nio.ch; 30 31 import java.lang.annotation.Native; 32 33 /** 34 * Manipulates a native array of structs corresponding to (fd, events) pairs. 35 * 36 * typedef struct pollfd { 37 * SOCKET fd; // 4 bytes 38 * short events; // 2 bytes 39 * } pollfd_t; 40 * 41 * @author Konstantin Kladko 42 * @author Mike McCloskey 43 */ 44 45 class PollArrayWrapper { 46 47 private AllocatedNativeObject pollArray; // The fd array 48 49 long pollArrayAddress; // pollArrayAddress 50 51 @Native private static final short FD_OFFSET = 0; // fd offset in pollfd 52 @Native private static final short EVENT_OFFSET = 4; // events offset in pollfd 53 54 static short SIZE_POLLFD = 8; // sizeof pollfd struct 55 56 // events masks 57 @Native static final short POLLIN = AbstractPollArrayWrapper.POLLIN; 58 @Native static final short POLLOUT = AbstractPollArrayWrapper.POLLOUT; 59 @Native static final short POLLERR = AbstractPollArrayWrapper.POLLERR; 60 @Native static final short POLLHUP = AbstractPollArrayWrapper.POLLHUP; 61 @Native static final short POLLNVAL = AbstractPollArrayWrapper.POLLNVAL; 62 @Native static final short POLLREMOVE = AbstractPollArrayWrapper.POLLREMOVE; 63 @Native static final short POLLCONN = 0x0002; 64 65 private int size; // Size of the pollArray 66 67 PollArrayWrapper(int newSize) { 68 int allocationSize = newSize * SIZE_POLLFD; 69 pollArray = new AllocatedNativeObject(allocationSize, true); 70 pollArrayAddress = pollArray.address(); 71 this.size = newSize; 72 } 73 74 // Prepare another pollfd struct for use. 75 void addEntry(int index, SelectionKeyImpl ski) { 76 putDescriptor(index, ski.channel.getFDVal()); 77 } 78 79 // Writes the pollfd entry from the source wrapper at the source index 80 // over the entry in the target wrapper at the target index. 81 void replaceEntry(PollArrayWrapper source, int sindex, 82 PollArrayWrapper target, int tindex) { 83 target.putDescriptor(tindex, source.getDescriptor(sindex)); |