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 * Manipulates a native array of pollfd structs. 30 * 31 * @author Mike McCloskey 32 * @since 1.4 33 */ 34 35 public abstract class AbstractPollArrayWrapper { 36 37 // Miscellaneous constants 38 static final short SIZE_POLLFD = 8; 39 static final short FD_OFFSET = 0; 40 static final short EVENT_OFFSET = 4; 41 static final short REVENT_OFFSET = 6; 42 43 // The poll fd array 44 protected AllocatedNativeObject pollArray; 45 46 // Number of valid entries in the pollArray 47 protected int totalChannels = 0; 48 49 // Base address of the native pollArray 50 protected long pollArrayAddress; 51 52 // Access methods for fd structures getEventOps(int i)53 int getEventOps(int i) { 54 int offset = SIZE_POLLFD * i + EVENT_OFFSET; 55 return pollArray.getShort(offset); 56 } 57 getReventOps(int i)58 int getReventOps(int i) { 59 int offset = SIZE_POLLFD * i + REVENT_OFFSET; 60 return pollArray.getShort(offset); 61 } 62 getDescriptor(int i)63 int getDescriptor(int i) { 64 int offset = SIZE_POLLFD * i + FD_OFFSET; 65 return pollArray.getInt(offset); 66 } 67 putEventOps(int i, int event)68 void putEventOps(int i, int event) { 69 int offset = SIZE_POLLFD * i + EVENT_OFFSET; 70 pollArray.putShort(offset, (short)event); 71 } 72 putReventOps(int i, int revent)73 void putReventOps(int i, int revent) { 74 int offset = SIZE_POLLFD * i + REVENT_OFFSET; 75 pollArray.putShort(offset, (short)revent); 76 } 77 putDescriptor(int i, int fd)78 void putDescriptor(int i, int fd) { 79 int offset = SIZE_POLLFD * i + FD_OFFSET; 80 pollArray.putInt(offset, fd); 81 } 82 83 } 84