Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/nio/ch/EPoll.java
32288 views
/*1* Copyright (c) 2008, 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 java.io.IOException;28import sun.misc.Unsafe;2930/**31* Provides access to the Linux epoll facility.32*/3334class EPoll {35private EPoll() { }3637private static final Unsafe unsafe = Unsafe.getUnsafe();3839/**40* typedef union epoll_data {41* void *ptr;42* int fd;43* __uint32_t u32;44* __uint64_t u64;45* } epoll_data_t;46*47* struct epoll_event {48* __uint32_t events;49* epoll_data_t data;50* }51*/52private static final int SIZEOF_EPOLLEVENT = eventSize();53private static final int OFFSETOF_EVENTS = eventsOffset();54private static final int OFFSETOF_FD = dataOffset();5556// opcodes57static final int EPOLL_CTL_ADD = 1;58static final int EPOLL_CTL_DEL = 2;59static final int EPOLL_CTL_MOD = 3;6061// flags62static final int EPOLLONESHOT = (1 << 30);6364/**65* Allocates a poll array to handle up to {@code count} events.66*/67static long allocatePollArray(int count) {68return unsafe.allocateMemory(count * SIZEOF_EPOLLEVENT);69}7071/**72* Free a poll array73*/74static void freePollArray(long address) {75unsafe.freeMemory(address);76}7778/**79* Returns event[i];80*/81static long getEvent(long address, int i) {82return address + (SIZEOF_EPOLLEVENT*i);83}8485/**86* Returns event->data.fd87*/88static int getDescriptor(long eventAddress) {89return unsafe.getInt(eventAddress + OFFSETOF_FD);90}9192/**93* Returns event->events94*/95static int getEvents(long eventAddress) {96return unsafe.getInt(eventAddress + OFFSETOF_EVENTS);97}9899// -- Native methods --100101private static native int eventSize();102103private static native int eventsOffset();104105private static native int dataOffset();106107static native int epollCreate() throws IOException;108109static native int epollCtl(int epfd, int opcode, int fd, int events);110111static native int epollWait(int epfd, long pollAddress, int numfds)112throws IOException;113114static {115IOUtil.load();116}117}118119120