1 /*
2 * Copyright (c) 2000, 2023, 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
117 }
118
119 JNIEXPORT jint JNICALL
120 Java_sun_nio_ch_IOUtil_fdVal(JNIEnv *env, jclass clazz, jobject fdo)
121 {
122 return fdval(env, fdo);
123 }
124
125 JNIEXPORT void JNICALL
126 Java_sun_nio_ch_IOUtil_setfdVal(JNIEnv *env, jclass clazz, jobject fdo, jint val)
127 {
128 setfdval(env, fdo, val);
129 }
130
131
132 #define SET_BLOCKING 0
133 #define SET_NONBLOCKING 1
134
135 JNIEXPORT void JNICALL
136 Java_sun_nio_ch_IOUtil_configureBlocking(JNIEnv *env, jclass clazz,
137 jobject fdo, jboolean blocking)
138 {
139 u_long argp;
140 int result = 0;
141 jint fd = fdval(env, fdo);
142
143 if (blocking == JNI_FALSE) {
144 argp = SET_NONBLOCKING;
145 } else {
146 argp = SET_BLOCKING;
147 /* Blocking fd cannot be registered with EventSelect */
148 WSAEventSelect(fd, NULL, 0);
149 }
150 result = ioctlsocket(fd, FIONBIO, &argp);
151 if (result == SOCKET_ERROR) {
152 NET_ThrowNew(env, WSAGetLastError(), "ioctlsocket");
153 }
154 }
155
156 JNIEXPORT jboolean JNICALL
157 Java_sun_nio_ch_IOUtil_drain(JNIEnv *env, jclass cl, jint fd)
158 {
159 char buf[16];
160 jboolean readBytes = JNI_FALSE;
161 for (;;) {
|
1 /*
2 * Copyright (c) 2000, 2025, 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
117 }
118
119 JNIEXPORT jint JNICALL
120 Java_sun_nio_ch_IOUtil_fdVal(JNIEnv *env, jclass clazz, jobject fdo)
121 {
122 return fdval(env, fdo);
123 }
124
125 JNIEXPORT void JNICALL
126 Java_sun_nio_ch_IOUtil_setfdVal(JNIEnv *env, jclass clazz, jobject fdo, jint val)
127 {
128 setfdval(env, fdo, val);
129 }
130
131
132 #define SET_BLOCKING 0
133 #define SET_NONBLOCKING 1
134
135 JNIEXPORT void JNICALL
136 Java_sun_nio_ch_IOUtil_configureBlocking(JNIEnv *env, jclass clazz,
137 jint fd, jboolean blocking)
138 {
139 u_long argp;
140 int result = 0;
141
142 if (blocking == JNI_FALSE) {
143 argp = SET_NONBLOCKING;
144 } else {
145 argp = SET_BLOCKING;
146 /* Blocking fd cannot be registered with EventSelect */
147 WSAEventSelect(fd, NULL, 0);
148 }
149 result = ioctlsocket(fd, FIONBIO, &argp);
150 if (result == SOCKET_ERROR) {
151 NET_ThrowNew(env, WSAGetLastError(), "ioctlsocket");
152 }
153 }
154
155 JNIEXPORT jboolean JNICALL
156 Java_sun_nio_ch_IOUtil_drain(JNIEnv *env, jclass cl, jint fd)
157 {
158 char buf[16];
159 jboolean readBytes = JNI_FALSE;
160 for (;;) {
|