Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/windows/native/libnio/ch/WEPollNatives.c
41134 views
1
/*
2
* Copyright (c) 2020, 2021, 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.h"
31
#include "nio_util.h"
32
#include "wepoll.h"
33
#include "sun_nio_ch_WEPoll.h"
34
35
JNIEXPORT jint JNICALL
36
Java_sun_nio_ch_WEPoll_eventSize(JNIEnv* env, jclass clazz)
37
{
38
return sizeof(struct epoll_event);
39
}
40
41
JNIEXPORT jint JNICALL
42
Java_sun_nio_ch_WEPoll_eventsOffset(JNIEnv* env, jclass clazz)
43
{
44
return offsetof(struct epoll_event, events);
45
}
46
47
JNIEXPORT jint JNICALL
48
Java_sun_nio_ch_WEPoll_dataOffset(JNIEnv* env, jclass clazz)
49
{
50
return offsetof(struct epoll_event, data);
51
}
52
53
JNIEXPORT jlong JNICALL
54
Java_sun_nio_ch_WEPoll_create(JNIEnv *env, jclass clazz) {
55
HANDLE h = epoll_create1(0);
56
if (h == NULL) {
57
JNU_ThrowIOExceptionWithLastError(env, "epoll_create1 failed");
58
}
59
return ptr_to_jlong(h);
60
}
61
62
JNIEXPORT jint JNICALL
63
Java_sun_nio_ch_WEPoll_ctl(JNIEnv *env, jclass clazz, jlong h,
64
jint opcode, jlong s, jint events)
65
{
66
struct epoll_event event;
67
int res;
68
SOCKET socket = (SOCKET) jlong_to_ptr(s);
69
70
event.events = (uint32_t) events;
71
event.data.sock = socket;
72
73
res = epoll_ctl(jlong_to_ptr(h), opcode, socket, &event);
74
return (res == 0) ? 0 : errno;
75
}
76
77
JNIEXPORT jint JNICALL
78
Java_sun_nio_ch_WEPoll_wait(JNIEnv *env, jclass clazz, jlong h,
79
jlong address, jint numfds, jint timeout)
80
{
81
struct epoll_event *events = jlong_to_ptr(address);
82
int res = epoll_wait(jlong_to_ptr(h), events, numfds, timeout);
83
if (res < 0) {
84
JNU_ThrowIOExceptionWithLastError(env, "epoll_wait failed");
85
return IOS_THROWN;
86
}
87
return res;
88
}
89
90
JNIEXPORT void JNICALL
91
Java_sun_nio_ch_WEPoll_close(JNIEnv *env, jclass clazz, jlong h) {
92
epoll_close(jlong_to_ptr(h));
93
}
94
95