30 #include "nio_util.h" |
30 #include "nio_util.h" |
31 |
31 |
32 #include <stdlib.h> |
32 #include <stdlib.h> |
33 #include <dlfcn.h> |
33 #include <dlfcn.h> |
34 #include <sys/types.h> |
34 #include <sys/types.h> |
35 #include <port.h> // Solaris 10 |
35 #include <port.h> |
36 |
36 |
37 #include "sun_nio_ch_SolarisEventPort.h" |
37 #include "sun_nio_ch_SolarisEventPort.h" |
38 |
38 |
39 JNIEXPORT void JNICALL |
|
40 Java_sun_nio_ch_SolarisEventPort_init(JNIEnv *env, jclass clazz) |
|
41 { |
|
42 } |
|
43 |
|
44 JNIEXPORT jint JNICALL |
39 JNIEXPORT jint JNICALL |
45 Java_sun_nio_ch_SolarisEventPort_portCreate |
40 Java_sun_nio_ch_SolarisEventPort_port_1create |
46 (JNIEnv* env, jclass clazz) |
41 (JNIEnv* env, jclass clazz) |
47 { |
42 { |
48 int port = port_create(); |
43 int port = port_create(); |
49 if (port == -1) { |
44 if (port == -1) { |
50 JNU_ThrowIOExceptionWithLastError(env, "port_create"); |
45 JNU_ThrowIOExceptionWithLastError(env, "port_create"); |
51 } |
46 } |
52 return (jint)port; |
47 return (jint)port; |
53 } |
48 } |
54 |
49 |
55 JNIEXPORT void JNICALL |
50 JNIEXPORT void JNICALL |
56 Java_sun_nio_ch_SolarisEventPort_portClose |
51 Java_sun_nio_ch_SolarisEventPort_port_1close |
57 (JNIEnv* env, jclass clazz, jint port) |
52 (JNIEnv* env, jclass clazz, jint port) |
58 { |
53 { |
59 int res; |
54 int res; |
60 RESTARTABLE(close(port), res); |
55 RESTARTABLE(close(port), res); |
61 } |
56 } |
62 |
57 |
63 JNIEXPORT void JNICALL |
58 JNIEXPORT jboolean JNICALL |
64 Java_sun_nio_ch_SolarisEventPort_portAssociate |
59 Java_sun_nio_ch_SolarisEventPort_port_1associate |
65 (JNIEnv* env, jclass clazz, jint port, jint source, jlong objectAddress, jint events) |
60 (JNIEnv* env, jclass clazz, jint port, jint source, jlong objectAddress, jint events) |
66 { |
61 { |
67 uintptr_t object = (uintptr_t)jlong_to_ptr(objectAddress); |
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 } |
68 |
71 |
69 if (port_associate((int)port, (int)source, object, (int)events, NULL) == -1) { |
72 JNIEXPORT jboolean JNICALL |
70 JNU_ThrowIOExceptionWithLastError(env, "port_associate"); |
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; |
71 } |
84 } |
72 } |
85 } |
73 |
86 |
74 JNIEXPORT void JNICALL |
87 JNIEXPORT void JNICALL |
75 Java_sun_nio_ch_SolarisEventPort_portDissociate |
88 Java_sun_nio_ch_SolarisEventPort_port_1send(JNIEnv* env, jclass clazz, |
76 (JNIEnv* env, jclass clazz, jint port, jint source, jlong objectAddress) |
|
77 { |
|
78 uintptr_t object = (uintptr_t)jlong_to_ptr(objectAddress); |
|
79 |
|
80 if (port_dissociate((int)port, (int)source, object) == -1) { |
|
81 JNU_ThrowIOExceptionWithLastError(env, "port_dissociate"); |
|
82 } |
|
83 } |
|
84 |
|
85 JNIEXPORT void JNICALL |
|
86 Java_sun_nio_ch_SolarisEventPort_portSend(JNIEnv* env, jclass clazz, |
|
87 jint port, jint events) |
89 jint port, jint events) |
88 { |
90 { |
89 if (port_send((int)port, (int)events, NULL) == -1) { |
91 if (port_send((int)port, (int)events, NULL) == -1) { |
90 JNU_ThrowIOExceptionWithLastError(env, "port_send"); |
92 JNU_ThrowIOExceptionWithLastError(env, "port_send"); |
91 } |
93 } |
92 } |
94 } |
93 |
95 |
94 JNIEXPORT void JNICALL |
96 JNIEXPORT void JNICALL |
95 Java_sun_nio_ch_SolarisEventPort_portGet(JNIEnv* env, jclass clazz, |
97 Java_sun_nio_ch_SolarisEventPort_port_1get(JNIEnv* env, jclass clazz, |
96 jint port, jlong eventAddress) |
98 jint port, jlong eventAddress) |
97 { |
99 { |
98 int res; |
100 int res; |
99 port_event_t* ev = (port_event_t*)jlong_to_ptr(eventAddress); |
101 port_event_t* ev = (port_event_t*)jlong_to_ptr(eventAddress); |
100 |
102 |
103 JNU_ThrowIOExceptionWithLastError(env, "port_get"); |
105 JNU_ThrowIOExceptionWithLastError(env, "port_get"); |
104 } |
106 } |
105 } |
107 } |
106 |
108 |
107 JNIEXPORT jint JNICALL |
109 JNIEXPORT jint JNICALL |
108 Java_sun_nio_ch_SolarisEventPort_portGetn(JNIEnv* env, jclass clazz, |
110 Java_sun_nio_ch_SolarisEventPort_port_1getn(JNIEnv* env, jclass clazz, |
109 jint port, jlong arrayAddress, jint max) |
111 jint port, jlong arrayAddress, jint max, jlong timeout) |
110 { |
112 { |
111 int res; |
113 int res; |
112 uint_t n = 1; |
114 uint_t n = 1; |
113 port_event_t* list = (port_event_t*)jlong_to_ptr(arrayAddress); |
115 port_event_t* list = (port_event_t*)jlong_to_ptr(arrayAddress); |
|
116 timespec_t ts; |
|
117 timespec_t* tsp; |
114 |
118 |
115 RESTARTABLE(port_getn((int)port, list, (uint_t)max, &n, NULL), res); |
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); |
116 if (res == -1) { |
128 if (res == -1) { |
117 JNU_ThrowIOExceptionWithLastError(env, "port_getn"); |
129 if (errno != ETIME && errno != EINTR) |
|
130 JNU_ThrowIOExceptionWithLastError(env, "port_getn"); |
118 } |
131 } |
|
132 |
119 return (jint)n; |
133 return (jint)n; |
120 } |
134 } |