< prev index next >

src/java.base/solaris/native/libnio/ch/SolarisEventPort.c

Print this page
rev 49271 : [mq]: selector-cleanup
   1 /*
   2  * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 





  26 #include "jni.h"
  27 #include "jni_util.h"
  28 #include "jvm.h"
  29 #include "jlong.h"

  30 #include "nio_util.h"
  31 
  32 #include <stdlib.h>
  33 #include <dlfcn.h>
  34 #include <sys/types.h>
  35 #include <port.h>
  36 
  37 #include "sun_nio_ch_SolarisEventPort.h"
  38 
  39 JNIEXPORT jint JNICALL
  40 Java_sun_nio_ch_SolarisEventPort_port_1create
  41     (JNIEnv* env, jclass clazz)
  42 {
  43     int port = port_create();
  44     if (port == -1) {
  45         JNU_ThrowIOExceptionWithLastError(env, "port_create");
  46     }
  47     return (jint)port;
  48 }
  49 
  50 JNIEXPORT void JNICALL
  51 Java_sun_nio_ch_SolarisEventPort_port_1close
  52     (JNIEnv* env, jclass clazz, jint port)
  53 {
  54     int res;
  55     RESTARTABLE(close(port), res);


  56 }
  57 
  58 JNIEXPORT jboolean JNICALL
  59 Java_sun_nio_ch_SolarisEventPort_port_1associate
  60     (JNIEnv* env, jclass clazz, jint port, jint source, jlong objectAddress, jint events)
  61 {
  62     uintptr_t object = (uintptr_t)jlong_to_ptr(objectAddress);
  63     if (port_associate((int)port, (int)source, object, (int)events, NULL) == 0) {
  64         return JNI_TRUE;
  65     } else {
  66         if (errno != EBADFD)
  67             JNU_ThrowIOExceptionWithLastError(env, "port_associate");
  68         return JNI_FALSE;
  69     }
  70 }
  71 
  72 JNIEXPORT jboolean JNICALL
  73 Java_sun_nio_ch_SolarisEventPort_port_1dissociate
  74     (JNIEnv* env, jclass clazz, jint port, jint source, jlong objectAddress)
  75 {
  76     uintptr_t object = (uintptr_t)jlong_to_ptr(objectAddress);
  77 
  78     if (port_dissociate((int)port, (int)source, object) == 0) {
  79         return JNI_TRUE;
  80     } else {
  81         if (errno != ENOENT)
  82             JNU_ThrowIOExceptionWithLastError(env, "port_dissociate");
  83         return JNI_FALSE;
  84     }
  85 }
  86 
  87 JNIEXPORT void JNICALL
  88 Java_sun_nio_ch_SolarisEventPort_port_1send(JNIEnv* env, jclass clazz,
  89     jint port, jint events)
  90 {
  91     if (port_send((int)port, (int)events, NULL) == -1) {
  92         JNU_ThrowIOExceptionWithLastError(env, "port_send");
  93     }
  94 }
  95 
  96 JNIEXPORT void JNICALL
  97 Java_sun_nio_ch_SolarisEventPort_port_1get(JNIEnv* env, jclass clazz,
  98     jint port, jlong eventAddress)
  99 {
 100     int res;
 101     port_event_t* ev = (port_event_t*)jlong_to_ptr(eventAddress);
 102 
 103     RESTARTABLE(port_get((int)port, ev, NULL), res);
 104     if (res == -1) {
 105         JNU_ThrowIOExceptionWithLastError(env, "port_get");




 106     }


 107 }
 108 
 109 JNIEXPORT jint JNICALL
 110 Java_sun_nio_ch_SolarisEventPort_port_1getn(JNIEnv* env, jclass clazz,
 111     jint port, jlong arrayAddress, jint max, jlong timeout)
 112 {
 113     int res;
 114     uint_t n = 1;
 115     port_event_t* list = (port_event_t*)jlong_to_ptr(arrayAddress);
 116     timespec_t ts;
 117     timespec_t* tsp;
 118 
 119     if (timeout >= 0L) {
 120         ts.tv_sec = timeout / 1000;
 121         ts.tv_nsec = 1000000 * (timeout % 1000);
 122         tsp = &ts;
 123     } else {
 124         tsp = NULL;
 125     }
 126 
 127     res = port_getn((int)port, list, (uint_t)max, &n, tsp);
 128     if (res == -1) {
 129         if (errno != ETIME && errno != EINTR)
 130             JNU_ThrowIOExceptionWithLastError(env, "port_getn");




 131     }
 132 
 133     return (jint)n;
 134 }
   1 /*
   2  * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include <stdlib.h>
  27 #include <dlfcn.h>
  28 #include <sys/types.h>
  29 #include <port.h>
  30 
  31 #include "jni.h"
  32 #include "jni_util.h"
  33 #include "jvm.h"
  34 #include "jlong.h"
  35 #include "nio.h"
  36 #include "nio_util.h"
  37 





  38 #include "sun_nio_ch_SolarisEventPort.h"
  39 
  40 JNIEXPORT jint JNICALL
  41 Java_sun_nio_ch_SolarisEventPort_port_1create
  42     (JNIEnv* env, jclass clazz)
  43 {
  44     int port = port_create();
  45     if (port == -1) {
  46         JNU_ThrowIOExceptionWithLastError(env, "port_create");
  47     }
  48     return (jint)port;
  49 }
  50 
  51 JNIEXPORT void JNICALL
  52 Java_sun_nio_ch_SolarisEventPort_port_1close
  53     (JNIEnv* env, jclass clazz, jint port)
  54 {
  55     int res = close(port);
  56     if (res < 0 && res != EINTR) {
  57         JNU_ThrowIOExceptionWithLastError(env, "close failed");
  58     }
  59 }
  60 
  61 JNIEXPORT jboolean JNICALL
  62 Java_sun_nio_ch_SolarisEventPort_port_1associate
  63     (JNIEnv* env, jclass clazz, jint port, jint source, jlong objectAddress, jint events)
  64 {
  65     uintptr_t object = (uintptr_t)jlong_to_ptr(objectAddress);
  66     if (port_associate((int)port, (int)source, object, (int)events, NULL) == 0) {
  67         return JNI_TRUE;
  68     } else {
  69         if (errno != EBADFD)
  70             JNU_ThrowIOExceptionWithLastError(env, "port_associate");
  71         return JNI_FALSE;
  72     }
  73 }
  74 
  75 JNIEXPORT jboolean JNICALL
  76 Java_sun_nio_ch_SolarisEventPort_port_1dissociate
  77     (JNIEnv* env, jclass clazz, jint port, jint source, jlong objectAddress)
  78 {
  79     uintptr_t object = (uintptr_t)jlong_to_ptr(objectAddress);
  80 
  81     if (port_dissociate((int)port, (int)source, object) == 0) {
  82         return JNI_TRUE;
  83     } else {
  84         if (errno != ENOENT)
  85             JNU_ThrowIOExceptionWithLastError(env, "port_dissociate");
  86         return JNI_FALSE;
  87     }
  88 }
  89 
  90 JNIEXPORT void JNICALL
  91 Java_sun_nio_ch_SolarisEventPort_port_1send(JNIEnv* env, jclass clazz,
  92     jint port, jint events)
  93 {
  94     if (port_send((int)port, (int)events, NULL) == -1) {
  95         JNU_ThrowIOExceptionWithLastError(env, "port_send");
  96     }
  97 }
  98 
  99 JNIEXPORT jint JNICALL
 100 Java_sun_nio_ch_SolarisEventPort_port_1get(JNIEnv* env, jclass clazz,
 101     jint port, jlong eventAddress)
 102 {
 103     int res;
 104     port_event_t* ev = (port_event_t*)jlong_to_ptr(eventAddress);
 105 
 106     res = port_get((int)port, ev, NULL);
 107     if (res == -1) {
 108         if (errno == EINTR) {
 109             return IOS_INTERRUPTED;
 110         } else {
 111             JNU_ThrowIOExceptionWithLastError(env, "port_get failed");
 112             return IOS_THROWN;
 113         }
 114     }
 115     return res;
 116 }
 117 
 118 JNIEXPORT jint JNICALL
 119 Java_sun_nio_ch_SolarisEventPort_port_1getn(JNIEnv* env, jclass clazz,
 120     jint port, jlong arrayAddress, jint max, jlong timeout)
 121 {
 122     int res;
 123     uint_t n = 1;
 124     port_event_t* list = (port_event_t*)jlong_to_ptr(arrayAddress);
 125     timespec_t ts;
 126     timespec_t* tsp;
 127 
 128     if (timeout >= 0L) {
 129         ts.tv_sec = timeout / 1000;
 130         ts.tv_nsec = 1000000 * (timeout % 1000);
 131         tsp = &ts;
 132     } else {
 133         tsp = NULL;
 134     }
 135 
 136     res = port_getn((int)port, list, (uint_t)max, &n, tsp);
 137     if (res == -1 && errno != ETIME) {
 138         if (errno == EINTR) {
 139             return IOS_INTERRUPTED;
 140         } else {
 141             JNU_ThrowIOExceptionWithLastError(env, "port_getn failed");
 142             return IOS_THROWN;
 143         }
 144     }
 145 
 146     return (jint)n;
 147 }
< prev index next >