Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/native/sun/nio/ch/Iocp.c
32288 views
1
/*
2
* Copyright (c) 2008, 2011, 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 <windows.h>
27
28
#include "jni.h"
29
#include "jni_util.h"
30
#include "jlong.h"
31
#include "nio.h"
32
#include "nio_util.h"
33
34
#include "sun_nio_ch_Iocp.h"
35
36
37
static jfieldID completionStatus_error;
38
static jfieldID completionStatus_bytesTransferred;
39
static jfieldID completionStatus_completionKey;
40
static jfieldID completionStatus_overlapped;
41
42
43
JNIEXPORT void JNICALL
44
Java_sun_nio_ch_Iocp_initIDs(JNIEnv* env, jclass this)
45
{
46
jclass clazz;
47
48
clazz = (*env)->FindClass(env, "sun/nio/ch/Iocp$CompletionStatus");
49
CHECK_NULL(clazz);
50
completionStatus_error = (*env)->GetFieldID(env, clazz, "error", "I");
51
CHECK_NULL(completionStatus_error);
52
completionStatus_bytesTransferred = (*env)->GetFieldID(env, clazz, "bytesTransferred", "I");
53
CHECK_NULL(completionStatus_bytesTransferred);
54
completionStatus_completionKey = (*env)->GetFieldID(env, clazz, "completionKey", "I");
55
CHECK_NULL(completionStatus_completionKey);
56
completionStatus_overlapped = (*env)->GetFieldID(env, clazz, "overlapped", "J");
57
CHECK_NULL(completionStatus_overlapped);
58
}
59
60
JNIEXPORT jint JNICALL
61
Java_sun_nio_ch_Iocp_osMajorVersion(JNIEnv* env, jclass this)
62
{
63
OSVERSIONINFOEX ver;
64
ver.dwOSVersionInfoSize = sizeof(ver);
65
GetVersionEx((OSVERSIONINFO *) &ver);
66
return (ver.dwPlatformId == VER_PLATFORM_WIN32_NT) ?
67
(jint)(ver.dwMajorVersion) : (jint)0;
68
}
69
70
JNIEXPORT jlong JNICALL
71
Java_sun_nio_ch_Iocp_createIoCompletionPort(JNIEnv* env, jclass this,
72
jlong handle, jlong existingPort, jint completionKey, jint concurrency)
73
{
74
ULONG_PTR ck = completionKey;
75
HANDLE port = CreateIoCompletionPort((HANDLE)jlong_to_ptr(handle),
76
(HANDLE)jlong_to_ptr(existingPort),
77
ck,
78
(DWORD)concurrency);
79
if (port == NULL) {
80
JNU_ThrowIOExceptionWithLastError(env, "CreateIoCompletionPort failed");
81
}
82
return ptr_to_jlong(port);
83
}
84
85
JNIEXPORT void JNICALL
86
Java_sun_nio_ch_Iocp_close0(JNIEnv* env, jclass this,
87
jlong handle)
88
{
89
HANDLE h = (HANDLE)jlong_to_ptr(handle);
90
CloseHandle(h);
91
}
92
93
94
JNIEXPORT void JNICALL
95
Java_sun_nio_ch_Iocp_getQueuedCompletionStatus(JNIEnv* env, jclass this,
96
jlong completionPort, jobject obj)
97
{
98
DWORD bytesTransferred;
99
ULONG_PTR completionKey;
100
OVERLAPPED *lpOverlapped;
101
BOOL res;
102
103
res = GetQueuedCompletionStatus((HANDLE)jlong_to_ptr(completionPort),
104
&bytesTransferred,
105
&completionKey,
106
&lpOverlapped,
107
INFINITE);
108
if (res == 0 && lpOverlapped == NULL) {
109
JNU_ThrowIOExceptionWithLastError(env, "GetQueuedCompletionStatus failed");
110
} else {
111
DWORD ioResult = (res == 0) ? GetLastError() : 0;
112
(*env)->SetIntField(env, obj, completionStatus_error, ioResult);
113
(*env)->SetIntField(env, obj, completionStatus_bytesTransferred,
114
(jint)bytesTransferred);
115
(*env)->SetIntField(env, obj, completionStatus_completionKey,
116
(jint)completionKey);
117
(*env)->SetLongField(env, obj, completionStatus_overlapped,
118
ptr_to_jlong(lpOverlapped));
119
120
}
121
}
122
123
JNIEXPORT void JNICALL
124
Java_sun_nio_ch_Iocp_postQueuedCompletionStatus(JNIEnv* env, jclass this,
125
jlong completionPort, jint completionKey)
126
{
127
BOOL res;
128
129
res = PostQueuedCompletionStatus((HANDLE)jlong_to_ptr(completionPort),
130
(DWORD)0,
131
(DWORD)completionKey,
132
NULL);
133
if (res == 0) {
134
JNU_ThrowIOExceptionWithLastError(env, "PostQueuedCompletionStatus");
135
}
136
}
137
138
JNIEXPORT jstring JNICALL
139
Java_sun_nio_ch_Iocp_getErrorMessage(JNIEnv* env, jclass this, jint errorCode)
140
{
141
WCHAR message[255];
142
143
DWORD len = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
144
NULL,
145
(DWORD)errorCode,
146
0,
147
&message[0],
148
255,
149
NULL);
150
151
152
if (len == 0) {
153
return NULL;
154
} else {
155
return (*env)->NewString(env, (const jchar *)message, (jsize)wcslen(message));
156
}
157
}
158
159