Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/sun/nio/ch/EPoll.c
32288 views
/*1* Copyright (c) 2008, 2011, 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*/2425#include "jni.h"26#include "jni_util.h"27#include "jvm.h"28#include "jlong.h"29#include "nio_util.h"3031#include "sun_nio_ch_EPoll.h"3233#include <dlfcn.h>34#include <unistd.h>35#include <sys/types.h>36#include <sys/epoll.h>3738JNIEXPORT jint JNICALL39Java_sun_nio_ch_EPoll_eventSize(JNIEnv* env, jclass this)40{41return sizeof(struct epoll_event);42}4344JNIEXPORT jint JNICALL45Java_sun_nio_ch_EPoll_eventsOffset(JNIEnv* env, jclass this)46{47return offsetof(struct epoll_event, events);48}4950JNIEXPORT jint JNICALL51Java_sun_nio_ch_EPoll_dataOffset(JNIEnv* env, jclass this)52{53return offsetof(struct epoll_event, data);54}5556JNIEXPORT jint JNICALL57Java_sun_nio_ch_EPoll_epollCreate(JNIEnv *env, jclass c) {58/*59* epoll_create expects a size as a hint to the kernel about how to60* dimension internal structures. We can't predict the size in advance.61*/62int epfd = epoll_create(256);63if (epfd < 0) {64JNU_ThrowIOExceptionWithLastError(env, "epoll_create failed");65}66return epfd;67}6869JNIEXPORT jint JNICALL70Java_sun_nio_ch_EPoll_epollCtl(JNIEnv *env, jclass c, jint epfd,71jint opcode, jint fd, jint events)72{73struct epoll_event event;74int res;7576event.events = events;77event.data.fd = fd;7879RESTARTABLE(epoll_ctl(epfd, (int)opcode, (int)fd, &event), res);8081return (res == 0) ? 0 : errno;82}8384JNIEXPORT jint JNICALL85Java_sun_nio_ch_EPoll_epollWait(JNIEnv *env, jclass c,86jint epfd, jlong address, jint numfds)87{88struct epoll_event *events = jlong_to_ptr(address);89int res;9091RESTARTABLE(epoll_wait(epfd, events, numfds, -1), res);92if (res < 0) {93JNU_ThrowIOExceptionWithLastError(env, "epoll_wait failed");94}95return res;96}9798JNIEXPORT void JNICALL99Java_sun_nio_ch_EPoll_close0(JNIEnv *env, jclass c, jint epfd) {100int res;101RESTARTABLE(close(epfd), res);102}103104105