author | michaelm |
Wed, 30 Oct 2019 11:53:07 +0000 | |
branch | unixdomainchannels |
changeset 58856 | b2f0339a4cad |
parent 49526 | cad4c844902a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
49493 | 2 |
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
/* |
|
27 |
*/ |
|
28 |
||
29 |
package sun.nio.ch; |
|
30 |
||
15136
c17824042364
8005856: build-infra: Remove special handling of base module classes header generation
erikj
parents:
5506
diff
changeset
|
31 |
import java.lang.annotation.Native; |
c17824042364
8005856: build-infra: Remove special handling of base module classes header generation
erikj
parents:
5506
diff
changeset
|
32 |
|
2 | 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 |
||
15136
c17824042364
8005856: build-infra: Remove special handling of base module classes header generation
erikj
parents:
5506
diff
changeset
|
51 |
@Native private static final short FD_OFFSET = 0; // fd offset in pollfd |
c17824042364
8005856: build-infra: Remove special handling of base module classes header generation
erikj
parents:
5506
diff
changeset
|
52 |
@Native private static final short EVENT_OFFSET = 4; // events offset in pollfd |
2 | 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. |
|
49493 | 66 |
void putEntry(int index, SelectionKeyImpl ski) { |
49526 | 67 |
putDescriptor(index, ski.getFDVal()); |
49493 | 68 |
putEventOps(index, 0); |
2 | 69 |
} |
70 |
||
71 |
// Writes the pollfd entry from the source wrapper at the source index |
|
72 |
// over the entry in the target wrapper at the target index. |
|
73 |
void replaceEntry(PollArrayWrapper source, int sindex, |
|
74 |
PollArrayWrapper target, int tindex) { |
|
75 |
target.putDescriptor(tindex, source.getDescriptor(sindex)); |
|
76 |
target.putEventOps(tindex, source.getEventOps(sindex)); |
|
77 |
} |
|
78 |
||
79 |
// Grows the pollfd array to new size |
|
80 |
void grow(int newSize) { |
|
81 |
PollArrayWrapper temp = new PollArrayWrapper(newSize); |
|
82 |
for (int i = 0; i < size; i++) |
|
83 |
replaceEntry(this, i, temp, i); |
|
84 |
pollArray.free(); |
|
85 |
pollArray = temp.pollArray; |
|
86 |
this.size = temp.size; |
|
87 |
pollArrayAddress = pollArray.address(); |
|
88 |
} |
|
89 |
||
90 |
void free() { |
|
91 |
pollArray.free(); |
|
92 |
} |
|
93 |
||
94 |
// Access methods for fd structures |
|
95 |
void putDescriptor(int i, int fd) { |
|
96 |
pollArray.putInt(SIZE_POLLFD * i + FD_OFFSET, fd); |
|
97 |
} |
|
98 |
||
99 |
void putEventOps(int i, int event) { |
|
100 |
pollArray.putShort(SIZE_POLLFD * i + EVENT_OFFSET, (short)event); |
|
101 |
} |
|
102 |
||
103 |
int getEventOps(int i) { |
|
104 |
return pollArray.getShort(SIZE_POLLFD * i + EVENT_OFFSET); |
|
105 |
} |
|
106 |
||
107 |
int getDescriptor(int i) { |
|
108 |
return pollArray.getInt(SIZE_POLLFD * i + FD_OFFSET); |
|
109 |
} |
|
110 |
||
111 |
// Adds Windows wakeup socket at a given index. |
|
112 |
void addWakeupSocket(int fdVal, int index) { |
|
113 |
putDescriptor(index, fdVal); |
|
22604
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
15136
diff
changeset
|
114 |
putEventOps(index, Net.POLLIN); |
2 | 115 |
} |
116 |
} |