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/classes/sun/nio/ch/PollArrayWrapper.java
32288 views
1
/*
2
* Copyright (c) 2001, 2013, 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
/*
27
*/
28
29
package sun.nio.ch;
30
31
import java.lang.annotation.Native;
32
33
/**
34
* Manipulates a native array of structs corresponding to (fd, events) pairs.
35
*
36
* typedef struct pollfd {
37
* SOCKET fd; // 4 bytes
38
* short events; // 2 bytes
39
* } pollfd_t;
40
*
41
* @author Konstantin Kladko
42
* @author Mike McCloskey
43
*/
44
45
class PollArrayWrapper {
46
47
private AllocatedNativeObject pollArray; // The fd array
48
49
long pollArrayAddress; // pollArrayAddress
50
51
@Native private static final short FD_OFFSET = 0; // fd offset in pollfd
52
@Native private static final short EVENT_OFFSET = 4; // events offset in pollfd
53
54
static short SIZE_POLLFD = 8; // sizeof pollfd struct
55
56
private int size; // Size of the pollArray
57
58
PollArrayWrapper(int newSize) {
59
int allocationSize = newSize * SIZE_POLLFD;
60
pollArray = new AllocatedNativeObject(allocationSize, true);
61
pollArrayAddress = pollArray.address();
62
this.size = newSize;
63
}
64
65
// Prepare another pollfd struct for use.
66
void addEntry(int index, SelectionKeyImpl ski) {
67
putDescriptor(index, ski.channel.getFDVal());
68
}
69
70
// Writes the pollfd entry from the source wrapper at the source index
71
// over the entry in the target wrapper at the target index.
72
void replaceEntry(PollArrayWrapper source, int sindex,
73
PollArrayWrapper target, int tindex) {
74
target.putDescriptor(tindex, source.getDescriptor(sindex));
75
target.putEventOps(tindex, source.getEventOps(sindex));
76
}
77
78
// Grows the pollfd array to new size
79
void grow(int newSize) {
80
PollArrayWrapper temp = new PollArrayWrapper(newSize);
81
for (int i = 0; i < size; i++)
82
replaceEntry(this, i, temp, i);
83
pollArray.free();
84
pollArray = temp.pollArray;
85
this.size = temp.size;
86
pollArrayAddress = pollArray.address();
87
}
88
89
void free() {
90
pollArray.free();
91
}
92
93
// Access methods for fd structures
94
void putDescriptor(int i, int fd) {
95
pollArray.putInt(SIZE_POLLFD * i + FD_OFFSET, fd);
96
}
97
98
void putEventOps(int i, int event) {
99
pollArray.putShort(SIZE_POLLFD * i + EVENT_OFFSET, (short)event);
100
}
101
102
int getEventOps(int i) {
103
return pollArray.getShort(SIZE_POLLFD * i + EVENT_OFFSET);
104
}
105
106
int getDescriptor(int i) {
107
return pollArray.getInt(SIZE_POLLFD * i + FD_OFFSET);
108
}
109
110
// Adds Windows wakeup socket at a given index.
111
void addWakeupSocket(int fdVal, int index) {
112
putDescriptor(index, fdVal);
113
putEventOps(index, Net.POLLIN);
114
}
115
}
116
117