Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/sun/nio/fs/SolarisWatchService.c
32288 views
/*1* Copyright (c) 2008, 2009, 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"2930#include <stdlib.h>31#include <dlfcn.h>32#include <sys/types.h>33#include <port.h> // Solaris 103435#include "sun_nio_fs_SolarisWatchService.h"3637static void throwUnixException(JNIEnv* env, int errnum) {38jobject x = JNU_NewObjectByName(env, "sun/nio/fs/UnixException",39"(I)V", errnum);40if (x != NULL) {41(*env)->Throw(env, x);42}43}4445JNIEXPORT void JNICALL46Java_sun_nio_fs_SolarisWatchService_init(JNIEnv *env, jclass clazz)47{48}4950JNIEXPORT jint JNICALL51Java_sun_nio_fs_SolarisWatchService_portCreate52(JNIEnv* env, jclass clazz)53{54int port = port_create();55if (port == -1) {56throwUnixException(env, errno);57}58return (jint)port;59}6061JNIEXPORT void JNICALL62Java_sun_nio_fs_SolarisWatchService_portAssociate63(JNIEnv* env, jclass clazz, jint port, jint source, jlong objectAddress, jint events)64{65uintptr_t object = (uintptr_t)jlong_to_ptr(objectAddress);6667if (port_associate((int)port, (int)source, object, (int)events, NULL) == -1) {68throwUnixException(env, errno);69}70}7172JNIEXPORT void JNICALL73Java_sun_nio_fs_SolarisWatchService_portDissociate74(JNIEnv* env, jclass clazz, jint port, jint source, jlong objectAddress)75{76uintptr_t object = (uintptr_t)jlong_to_ptr(objectAddress);7778if (port_dissociate((int)port, (int)source, object) == -1) {79throwUnixException(env, errno);80}81}8283JNIEXPORT void JNICALL84Java_sun_nio_fs_SolarisWatchService_portSend(JNIEnv* env, jclass clazz,85jint port, jint events)86{87if (port_send((int)port, (int)events, NULL) == -1) {88throwUnixException(env, errno);89}90}9192JNIEXPORT jint JNICALL93Java_sun_nio_fs_SolarisWatchService_portGetn(JNIEnv* env, jclass clazz,94jint port, jlong arrayAddress, jint max)95{96uint_t n = 1;97port_event_t* list = (port_event_t*)jlong_to_ptr(arrayAddress);9899if (port_getn((int)port, list, (uint_t)max, &n, NULL) == -1) {100throwUnixException(env, errno);101}102return (jint)n;103}104105106