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 package sun.nio.ch;
27
28 import java.io.*;
29 import java.nio.ByteBuffer;
30 import java.nio.channels.*;
31 import java.nio.channels.spi.*;
32
33
34 class SinkChannelImpl
35 extends Pipe.SinkChannel
36 implements SelChImpl
37 {
38
39 // Used to make native read and write calls
40 private static NativeDispatcher nd;
41
42 // The file descriptor associated with this channel
43 FileDescriptor fd;
44
45 // fd value needed for dev/poll. This value will remain valid
46 // even after the value in the file descriptor object has been set to -1
47 int fdVal;
48
49 // ID of native thread doing write, for signalling
50 private volatile long thread = 0;
51
52 // Lock held by current reading thread
53 private final Object lock = new Object();
54
55 // Lock held by any thread that modifies the state fields declared below
56 // DO NOT invoke a blocking I/O operation while holding this lock!
57 private final Object stateLock = new Object();
58
59 // -- The following fields are protected by stateLock
60
188 thread = NativeThread.current();
189 do {
190 n = IOUtil.write(fd, srcs, nd);
191 } while ((n == IOStatus.INTERRUPTED) && isOpen());
192 return IOStatus.normalize(n);
193 } finally {
194 thread = 0;
195 end((n > 0) || (n == IOStatus.UNAVAILABLE));
196 assert IOStatus.check(n);
197 }
198 }
199 }
200
201 public long write(ByteBuffer[] srcs, int offset, int length)
202 throws IOException
203 {
204 if ((offset < 0) || (length < 0) || (offset > srcs.length - length))
205 throw new IndexOutOfBoundsException();
206 return write(Util.subsequence(srcs, offset, length));
207 }
208
209 static {
210 Util.load();
211 nd = new FileDispatcher();
212 }
213
214 }
|
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 package sun.nio.ch;
27
28 import java.io.*;
29 import java.nio.ByteBuffer;
30 import java.nio.channels.*;
31 import java.nio.channels.spi.*;
32
33
34 class SinkChannelImpl
35 extends Pipe.SinkChannel
36 implements SelChImpl
37 {
38
39 // Used to make native read and write calls
40 private static final NativeDispatcher nd = new FileDispatcher();
41
42 // The file descriptor associated with this channel
43 FileDescriptor fd;
44
45 // fd value needed for dev/poll. This value will remain valid
46 // even after the value in the file descriptor object has been set to -1
47 int fdVal;
48
49 // ID of native thread doing write, for signalling
50 private volatile long thread = 0;
51
52 // Lock held by current reading thread
53 private final Object lock = new Object();
54
55 // Lock held by any thread that modifies the state fields declared below
56 // DO NOT invoke a blocking I/O operation while holding this lock!
57 private final Object stateLock = new Object();
58
59 // -- The following fields are protected by stateLock
60
188 thread = NativeThread.current();
189 do {
190 n = IOUtil.write(fd, srcs, nd);
191 } while ((n == IOStatus.INTERRUPTED) && isOpen());
192 return IOStatus.normalize(n);
193 } finally {
194 thread = 0;
195 end((n > 0) || (n == IOStatus.UNAVAILABLE));
196 assert IOStatus.check(n);
197 }
198 }
199 }
200
201 public long write(ByteBuffer[] srcs, int offset, int length)
202 throws IOException
203 {
204 if ((offset < 0) || (length < 0) || (offset > srcs.length - length))
205 throw new IndexOutOfBoundsException();
206 return write(Util.subsequence(srcs, offset, length));
207 }
208 }
|