Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/windows/classes/sun/nio/ch/SinkChannelImpl.java
41139 views
1
/*
2
* Copyright (c) 2002, 2020, 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.io.IOException;
32
import java.io.FileDescriptor;
33
import java.net.SocketOption;
34
import java.nio.ByteBuffer;
35
import java.nio.channels.*;
36
import java.nio.channels.spi.*;
37
38
39
/**
40
* Pipe.SinkChannel implementation based on socket connection.
41
*/
42
43
class SinkChannelImpl
44
extends Pipe.SinkChannel
45
implements SelChImpl
46
{
47
// The SocketChannel assoicated with this pipe
48
private final SocketChannelImpl sc;
49
50
public FileDescriptor getFD() {
51
return sc.getFD();
52
}
53
54
public int getFDVal() {
55
return sc.getFDVal();
56
}
57
58
SinkChannelImpl(SelectorProvider sp, SocketChannel sc) {
59
super(sp);
60
this.sc = (SocketChannelImpl) sc;
61
}
62
63
boolean isNetSocket() {
64
return sc.isNetSocket();
65
}
66
67
<T> void setOption(SocketOption<T> name, T value) throws IOException {
68
sc.setOption(name, value);
69
}
70
71
protected void implCloseSelectableChannel() throws IOException {
72
if (!isRegistered())
73
kill();
74
}
75
76
public void kill() throws IOException {
77
sc.close();
78
}
79
80
protected void implConfigureBlocking(boolean block) throws IOException {
81
sc.configureBlocking(block);
82
}
83
84
public boolean translateReadyOps(int ops, int initialOps, SelectionKeyImpl ski) {
85
int intOps = ski.nioInterestOps();
86
int oldOps = ski.nioReadyOps();
87
int newOps = initialOps;
88
89
if ((ops & Net.POLLNVAL) != 0)
90
throw new Error("POLLNVAL detected");
91
92
if ((ops & (Net.POLLERR | Net.POLLHUP)) != 0) {
93
newOps = intOps;
94
ski.nioReadyOps(newOps);
95
return (newOps & ~oldOps) != 0;
96
}
97
98
if (((ops & Net.POLLOUT) != 0) &&
99
((intOps & SelectionKey.OP_WRITE) != 0))
100
newOps |= SelectionKey.OP_WRITE;
101
102
ski.nioReadyOps(newOps);
103
return (newOps & ~oldOps) != 0;
104
}
105
106
public boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl ski) {
107
return translateReadyOps(ops, ski.nioReadyOps(), ski);
108
}
109
110
public boolean translateAndSetReadyOps(int ops, SelectionKeyImpl ski) {
111
return translateReadyOps(ops, 0, ski);
112
}
113
114
public int translateInterestOps(int ops) {
115
int newOps = 0;
116
if ((ops & SelectionKey.OP_WRITE) != 0)
117
newOps |= Net.POLLOUT;
118
return newOps;
119
}
120
121
public int write(ByteBuffer src) throws IOException {
122
try {
123
return sc.write(src);
124
} catch (AsynchronousCloseException x) {
125
close();
126
throw x;
127
}
128
}
129
130
public long write(ByteBuffer[] srcs) throws IOException {
131
try {
132
return sc.write(srcs);
133
} catch (AsynchronousCloseException x) {
134
close();
135
throw x;
136
}
137
}
138
139
public long write(ByteBuffer[] srcs, int offset, int length)
140
throws IOException
141
{
142
if ((offset < 0) || (length < 0) || (offset > srcs.length - length))
143
throw new IndexOutOfBoundsException();
144
try {
145
return write(Util.subsequence(srcs, offset, length));
146
} catch (AsynchronousCloseException x) {
147
close();
148
throw x;
149
}
150
}
151
}
152
153