Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/sun/nio/ch/KQueue.c
32288 views
/*1* Copyright (c) 2012, 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_KQueue.h"3233#include <strings.h>34#include <sys/types.h>35#include <sys/event.h>36#include <sys/time.h>3738JNIEXPORT jint JNICALL39Java_sun_nio_ch_KQueue_keventSize(JNIEnv* env, jclass this)40{41return sizeof(struct kevent);42}4344JNIEXPORT jint JNICALL45Java_sun_nio_ch_KQueue_identOffset(JNIEnv* env, jclass this)46{47return offsetof(struct kevent, ident);48}4950JNIEXPORT jint JNICALL51Java_sun_nio_ch_KQueue_filterOffset(JNIEnv* env, jclass this)52{53return offsetof(struct kevent, filter);54}5556JNIEXPORT jint JNICALL57Java_sun_nio_ch_KQueue_flagsOffset(JNIEnv* env, jclass this)58{59return offsetof(struct kevent, flags);60}6162JNIEXPORT jint JNICALL63Java_sun_nio_ch_KQueue_kqueue(JNIEnv *env, jclass c) {64int kqfd = kqueue();65if (kqfd < 0) {66JNU_ThrowIOExceptionWithLastError(env, "kqueue failed");67}68return kqfd;69}7071JNIEXPORT jint JNICALL72Java_sun_nio_ch_KQueue_keventRegister(JNIEnv *env, jclass c, jint kqfd,73jint fd, jint filter, jint flags)7475{76struct kevent changes[1];77struct timespec timeout = {0, 0};78int res;7980EV_SET(&changes[0], fd, filter, flags, 0, 0, 0);81RESTARTABLE(kevent(kqfd, &changes[0], 1, NULL, 0, &timeout), res);82return (res == -1) ? errno : 0;83}8485JNIEXPORT jint JNICALL86Java_sun_nio_ch_KQueue_keventPoll(JNIEnv *env, jclass c,87jint kqfd, jlong address, jint nevents)88{89struct kevent *events = jlong_to_ptr(address);90int res;9192RESTARTABLE(kevent(kqfd, NULL, 0, events, nevents, NULL), res);93if (res < 0) {94JNU_ThrowIOExceptionWithLastError(env, "kqueue failed");95}96return res;97}9899100