Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/linux/native/libnio/ch/EPoll.c
41133 views
1
/*
2
* Copyright (c) 2008, 2020, 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 <dlfcn.h>
27
#include <unistd.h>
28
#include <sys/types.h>
29
#include <sys/epoll.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_EPoll.h"
39
40
JNIEXPORT jint JNICALL
41
Java_sun_nio_ch_EPoll_eventSize(JNIEnv* env, jclass clazz)
42
{
43
return sizeof(struct epoll_event);
44
}
45
46
JNIEXPORT jint JNICALL
47
Java_sun_nio_ch_EPoll_eventsOffset(JNIEnv* env, jclass clazz)
48
{
49
return offsetof(struct epoll_event, events);
50
}
51
52
JNIEXPORT jint JNICALL
53
Java_sun_nio_ch_EPoll_dataOffset(JNIEnv* env, jclass clazz)
54
{
55
return offsetof(struct epoll_event, data);
56
}
57
58
JNIEXPORT jint JNICALL
59
Java_sun_nio_ch_EPoll_create(JNIEnv *env, jclass clazz) {
60
int epfd = epoll_create1(EPOLL_CLOEXEC);
61
if (epfd < 0) {
62
JNU_ThrowIOExceptionWithLastError(env, "epoll_create1 failed");
63
}
64
return epfd;
65
}
66
67
JNIEXPORT jint JNICALL
68
Java_sun_nio_ch_EPoll_ctl(JNIEnv *env, jclass clazz, jint epfd,
69
jint opcode, jint fd, jint events)
70
{
71
struct epoll_event event;
72
int res;
73
74
event.events = events;
75
event.data.fd = fd;
76
77
res = epoll_ctl(epfd, (int)opcode, (int)fd, &event);
78
return (res == 0) ? 0 : errno;
79
}
80
81
JNIEXPORT jint JNICALL
82
Java_sun_nio_ch_EPoll_wait(JNIEnv *env, jclass clazz, jint epfd,
83
jlong address, jint numfds, jint timeout)
84
{
85
struct epoll_event *events = jlong_to_ptr(address);
86
int res = epoll_wait(epfd, events, numfds, timeout);
87
if (res < 0) {
88
if (errno == EINTR) {
89
return IOS_INTERRUPTED;
90
} else {
91
JNU_ThrowIOExceptionWithLastError(env, "epoll_wait failed");
92
return IOS_THROWN;
93
}
94
}
95
return res;
96
}
97
98