author | igerasim |
Tue, 28 Oct 2014 15:36:27 +0300 | |
changeset 27263 | 819f5f87d485 |
parent 25859 | 3317bb8137f4 |
child 36966 | 4209c9e19c45 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
22604
diff
changeset
|
2 |
* Copyright (c) 2001, 2013, 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 |
|
46 |
// File descriptor to write for interrupt |
|
47 |
int interruptFD; |
|
48 |
||
49 |
PollArrayWrapper(int newSize) { |
|
50 |
newSize = (newSize + 1) * SIZE_POLLFD; |
|
51 |
pollArray = new AllocatedNativeObject(newSize, false); |
|
52 |
pollArrayAddress = pollArray.address(); |
|
53 |
totalChannels = 1; |
|
54 |
} |
|
55 |
||
56 |
void initInterrupt(int fd0, int fd1) { |
|
57 |
interruptFD = fd1; |
|
58 |
putDescriptor(0, fd0); |
|
22604
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
59 |
putEventOps(0, Net.POLLIN); |
2 | 60 |
putReventOps(0, 0); |
61 |
} |
|
62 |
||
63 |
void release(int i) { |
|
64 |
return; |
|
65 |
} |
|
66 |
||
67 |
void free() { |
|
68 |
pollArray.free(); |
|
69 |
} |
|
70 |
||
71 |
/** |
|
72 |
* Prepare another pollfd struct for use. |
|
73 |
*/ |
|
74 |
void addEntry(SelChImpl sc) { |
|
75 |
putDescriptor(totalChannels, IOUtil.fdVal(sc.getFD())); |
|
76 |
putEventOps(totalChannels, 0); |
|
77 |
putReventOps(totalChannels, 0); |
|
78 |
totalChannels++; |
|
79 |
} |
|
80 |
||
81 |
/** |
|
82 |
* Writes the pollfd entry from the source wrapper at the source index |
|
83 |
* over the entry in the target wrapper at the target index. The source |
|
84 |
* array remains unchanged unless the source array and the target are |
|
85 |
* the same array. |
|
86 |
*/ |
|
87 |
static void replaceEntry(PollArrayWrapper source, int sindex, |
|
88 |
PollArrayWrapper target, int tindex) { |
|
89 |
target.putDescriptor(tindex, source.getDescriptor(sindex)); |
|
90 |
target.putEventOps(tindex, source.getEventOps(sindex)); |
|
91 |
target.putReventOps(tindex, source.getReventOps(sindex)); |
|
92 |
} |
|
93 |
||
94 |
/** |
|
95 |
* Grows the pollfd array to a size that will accommodate newSize |
|
96 |
* pollfd entries. This method does no checking of the newSize |
|
97 |
* to determine if it is in fact bigger than the old size: it |
|
98 |
* always reallocates an array of the new size. |
|
99 |
*/ |
|
100 |
void grow(int newSize) { |
|
101 |
// create new array |
|
102 |
PollArrayWrapper temp = new PollArrayWrapper(newSize); |
|
103 |
||
104 |
// Copy over existing entries |
|
105 |
for (int i=0; i<totalChannels; i++) |
|
106 |
replaceEntry(this, i, temp, i); |
|
107 |
||
108 |
// Swap new array into pollArray field |
|
109 |
pollArray.free(); |
|
110 |
pollArray = temp.pollArray; |
|
111 |
pollArrayAddress = pollArray.address(); |
|
112 |
} |
|
113 |
||
114 |
int poll(int numfds, int offset, long timeout) { |
|
115 |
return poll0(pollArrayAddress + (offset * SIZE_POLLFD), |
|
116 |
numfds, timeout); |
|
117 |
} |
|
118 |
||
119 |
public void interrupt() { |
|
120 |
interrupt(interruptFD); |
|
121 |
} |
|
122 |
||
123 |
private native int poll0(long pollAddress, int numfds, long timeout); |
|
124 |
||
125 |
private static native void interrupt(int fd); |
|
126 |
||
19607
bee007586d06
8022594: Potential deadlock in <clinit> of sun.nio.ch.Util/IOUtil
alanb
parents:
14342
diff
changeset
|
127 |
static { |
bee007586d06
8022594: Potential deadlock in <clinit> of sun.nio.ch.Util/IOUtil
alanb
parents:
14342
diff
changeset
|
128 |
IOUtil.load(); |
bee007586d06
8022594: Potential deadlock in <clinit> of sun.nio.ch.Util/IOUtil
alanb
parents:
14342
diff
changeset
|
129 |
} |
2 | 130 |
} |