author | alanb |
Wed, 28 Aug 2013 15:50:03 +0100 | |
changeset 19607 | bee007586d06 |
parent 14342 | 8435a30053c1 |
child 22604 | 9b394795e216 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
11823
diff
changeset
|
2 |
* Copyright (c) 2001, 2012, 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 |
package sun.nio.ch; |
|
27 |
||
28 |
import sun.misc.*; |
|
29 |
||
30 |
||
31 |
/** |
|
32 |
* Manipulates a native array of pollfd structs on Solaris: |
|
33 |
* |
|
34 |
* typedef struct pollfd { |
|
35 |
* int fd; |
|
36 |
* short events; |
|
37 |
* short revents; |
|
38 |
* } pollfd_t; |
|
39 |
* |
|
40 |
* @author Mike McCloskey |
|
41 |
* @since 1.4 |
|
42 |
*/ |
|
43 |
||
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
44 |
public class PollArrayWrapper extends AbstractPollArrayWrapper { |
2 | 45 |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
46 |
public static final short POLLCONN = POLLOUT; |
2 | 47 |
|
48 |
// File descriptor to write for interrupt |
|
49 |
int interruptFD; |
|
50 |
||
51 |
PollArrayWrapper(int newSize) { |
|
52 |
newSize = (newSize + 1) * SIZE_POLLFD; |
|
53 |
pollArray = new AllocatedNativeObject(newSize, false); |
|
54 |
pollArrayAddress = pollArray.address(); |
|
55 |
totalChannels = 1; |
|
56 |
} |
|
57 |
||
58 |
void initInterrupt(int fd0, int fd1) { |
|
59 |
interruptFD = fd1; |
|
60 |
putDescriptor(0, fd0); |
|
61 |
putEventOps(0, POLLIN); |
|
62 |
putReventOps(0, 0); |
|
63 |
} |
|
64 |
||
65 |
void release(int i) { |
|
66 |
return; |
|
67 |
} |
|
68 |
||
69 |
void free() { |
|
70 |
pollArray.free(); |
|
71 |
} |
|
72 |
||
73 |
/** |
|
74 |
* Prepare another pollfd struct for use. |
|
75 |
*/ |
|
76 |
void addEntry(SelChImpl sc) { |
|
77 |
putDescriptor(totalChannels, IOUtil.fdVal(sc.getFD())); |
|
78 |
putEventOps(totalChannels, 0); |
|
79 |
putReventOps(totalChannels, 0); |
|
80 |
totalChannels++; |
|
81 |
} |
|
82 |
||
83 |
/** |
|
84 |
* Writes the pollfd entry from the source wrapper at the source index |
|
85 |
* over the entry in the target wrapper at the target index. The source |
|
86 |
* array remains unchanged unless the source array and the target are |
|
87 |
* the same array. |
|
88 |
*/ |
|
89 |
static void replaceEntry(PollArrayWrapper source, int sindex, |
|
90 |
PollArrayWrapper target, int tindex) { |
|
91 |
target.putDescriptor(tindex, source.getDescriptor(sindex)); |
|
92 |
target.putEventOps(tindex, source.getEventOps(sindex)); |
|
93 |
target.putReventOps(tindex, source.getReventOps(sindex)); |
|
94 |
} |
|
95 |
||
96 |
/** |
|
97 |
* Grows the pollfd array to a size that will accommodate newSize |
|
98 |
* pollfd entries. This method does no checking of the newSize |
|
99 |
* to determine if it is in fact bigger than the old size: it |
|
100 |
* always reallocates an array of the new size. |
|
101 |
*/ |
|
102 |
void grow(int newSize) { |
|
103 |
// create new array |
|
104 |
PollArrayWrapper temp = new PollArrayWrapper(newSize); |
|
105 |
||
106 |
// Copy over existing entries |
|
107 |
for (int i=0; i<totalChannels; i++) |
|
108 |
replaceEntry(this, i, temp, i); |
|
109 |
||
110 |
// Swap new array into pollArray field |
|
111 |
pollArray.free(); |
|
112 |
pollArray = temp.pollArray; |
|
113 |
pollArrayAddress = pollArray.address(); |
|
114 |
} |
|
115 |
||
116 |
int poll(int numfds, int offset, long timeout) { |
|
117 |
return poll0(pollArrayAddress + (offset * SIZE_POLLFD), |
|
118 |
numfds, timeout); |
|
119 |
} |
|
120 |
||
121 |
public void interrupt() { |
|
122 |
interrupt(interruptFD); |
|
123 |
} |
|
124 |
||
125 |
private native int poll0(long pollAddress, int numfds, long timeout); |
|
126 |
||
127 |
private static native void interrupt(int fd); |
|
128 |
||
19607
bee007586d06
8022594: Potential deadlock in <clinit> of sun.nio.ch.Util/IOUtil
alanb
parents:
14342
diff
changeset
|
129 |
static { |
bee007586d06
8022594: Potential deadlock in <clinit> of sun.nio.ch.Util/IOUtil
alanb
parents:
14342
diff
changeset
|
130 |
IOUtil.load(); |
bee007586d06
8022594: Potential deadlock in <clinit> of sun.nio.ch.Util/IOUtil
alanb
parents:
14342
diff
changeset
|
131 |
} |
2 | 132 |
} |