Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/nio/ch/PollArrayWrapper.java
32288 views
/*1* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.nio.ch;2627import sun.misc.*;282930/**31* Manipulates a native array of pollfd structs on Solaris:32*33* typedef struct pollfd {34* int fd;35* short events;36* short revents;37* } pollfd_t;38*39* @author Mike McCloskey40* @since 1.441*/4243public class PollArrayWrapper extends AbstractPollArrayWrapper {4445// File descriptor to write for interrupt46int interruptFD;4748PollArrayWrapper(int newSize) {49newSize = (newSize + 1) * SIZE_POLLFD;50pollArray = new AllocatedNativeObject(newSize, false);51pollArrayAddress = pollArray.address();52totalChannels = 1;53}5455void initInterrupt(int fd0, int fd1) {56interruptFD = fd1;57putDescriptor(0, fd0);58putEventOps(0, Net.POLLIN);59putReventOps(0, 0);60}6162void release(int i) {63return;64}6566void free() {67pollArray.free();68}6970/**71* Prepare another pollfd struct for use.72*/73void addEntry(SelChImpl sc) {74putDescriptor(totalChannels, IOUtil.fdVal(sc.getFD()));75putEventOps(totalChannels, 0);76putReventOps(totalChannels, 0);77totalChannels++;78}7980/**81* Writes the pollfd entry from the source wrapper at the source index82* over the entry in the target wrapper at the target index. The source83* array remains unchanged unless the source array and the target are84* the same array.85*/86static void replaceEntry(PollArrayWrapper source, int sindex,87PollArrayWrapper target, int tindex) {88target.putDescriptor(tindex, source.getDescriptor(sindex));89target.putEventOps(tindex, source.getEventOps(sindex));90target.putReventOps(tindex, source.getReventOps(sindex));91}9293/**94* Grows the pollfd array to a size that will accommodate newSize95* pollfd entries. This method does no checking of the newSize96* to determine if it is in fact bigger than the old size: it97* always reallocates an array of the new size.98*/99void grow(int newSize) {100// create new array101PollArrayWrapper temp = new PollArrayWrapper(newSize);102103// Copy over existing entries104for (int i=0; i<totalChannels; i++)105replaceEntry(this, i, temp, i);106107// Swap new array into pollArray field108pollArray.free();109pollArray = temp.pollArray;110pollArrayAddress = pollArray.address();111}112113int poll(int numfds, int offset, long timeout) {114return poll0(pollArrayAddress + (offset * SIZE_POLLFD),115numfds, timeout);116}117118public void interrupt() {119interrupt(interruptFD);120}121122private native int poll0(long pollAddress, int numfds, long timeout);123124private static native void interrupt(int fd);125126static {127IOUtil.load();128}129}130131132