Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/sun/nio/ch/SolarisEventPort.c
32288 views
/*1* Copyright (c) 2008, 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 <stdlib.h>32#include <dlfcn.h>33#include <sys/types.h>34#include <port.h>3536#include "sun_nio_ch_SolarisEventPort.h"3738JNIEXPORT jint JNICALL39Java_sun_nio_ch_SolarisEventPort_port_1create40(JNIEnv* env, jclass clazz)41{42int port = port_create();43if (port == -1) {44JNU_ThrowIOExceptionWithLastError(env, "port_create");45}46return (jint)port;47}4849JNIEXPORT void JNICALL50Java_sun_nio_ch_SolarisEventPort_port_1close51(JNIEnv* env, jclass clazz, jint port)52{53int res;54RESTARTABLE(close(port), res);55}5657JNIEXPORT jboolean JNICALL58Java_sun_nio_ch_SolarisEventPort_port_1associate59(JNIEnv* env, jclass clazz, jint port, jint source, jlong objectAddress, jint events)60{61uintptr_t object = (uintptr_t)jlong_to_ptr(objectAddress);62if (port_associate((int)port, (int)source, object, (int)events, NULL) == 0) {63return JNI_TRUE;64} else {65if (errno != EBADFD)66JNU_ThrowIOExceptionWithLastError(env, "port_associate");67return JNI_FALSE;68}69}7071JNIEXPORT jboolean JNICALL72Java_sun_nio_ch_SolarisEventPort_port_1dissociate73(JNIEnv* env, jclass clazz, jint port, jint source, jlong objectAddress)74{75uintptr_t object = (uintptr_t)jlong_to_ptr(objectAddress);7677if (port_dissociate((int)port, (int)source, object) == 0) {78return JNI_TRUE;79} else {80if (errno != ENOENT)81JNU_ThrowIOExceptionWithLastError(env, "port_dissociate");82return JNI_FALSE;83}84}8586JNIEXPORT void JNICALL87Java_sun_nio_ch_SolarisEventPort_port_1send(JNIEnv* env, jclass clazz,88jint port, jint events)89{90if (port_send((int)port, (int)events, NULL) == -1) {91JNU_ThrowIOExceptionWithLastError(env, "port_send");92}93}9495JNIEXPORT void JNICALL96Java_sun_nio_ch_SolarisEventPort_port_1get(JNIEnv* env, jclass clazz,97jint port, jlong eventAddress)98{99int res;100port_event_t* ev = (port_event_t*)jlong_to_ptr(eventAddress);101102RESTARTABLE(port_get((int)port, ev, NULL), res);103if (res == -1) {104JNU_ThrowIOExceptionWithLastError(env, "port_get");105}106}107108JNIEXPORT jint JNICALL109Java_sun_nio_ch_SolarisEventPort_port_1getn(JNIEnv* env, jclass clazz,110jint port, jlong arrayAddress, jint max, jlong timeout)111{112int res;113uint_t n = 1;114port_event_t* list = (port_event_t*)jlong_to_ptr(arrayAddress);115timespec_t ts;116timespec_t* tsp;117118if (timeout >= 0L) {119ts.tv_sec = timeout / 1000;120ts.tv_nsec = 1000000 * (timeout % 1000);121tsp = &ts;122} else {123tsp = NULL;124}125126res = port_getn((int)port, list, (uint_t)max, &n, tsp);127if (res == -1) {128if (errno != ETIME && errno != EINTR)129JNU_ThrowIOExceptionWithLastError(env, "port_getn");130}131132return (jint)n;133}134135136