author | michaelm |
Sat, 12 Apr 2014 20:21:09 +0100 | |
changeset 23879 | 284802a2d355 |
parent 5506 | 202f599c92aa |
child 24046 | d1f6da65881a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2007, 2008, 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 |
package java.net; |
|
26 |
||
27 |
import java.io.IOException; |
|
28 |
import java.io.FileDescriptor; |
|
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
29 |
import java.util.Set; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
30 |
import java.util.HashSet; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
31 |
import java.util.Collections; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
32 |
import jdk.net.*; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
33 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
34 |
import static sun.net.ExtendedOptionsImpl.*; |
2 | 35 |
|
36 |
/* |
|
37 |
* On Unix systems we simply delegate to native methods. |
|
38 |
* |
|
39 |
* @author Chris Hegarty |
|
40 |
*/ |
|
41 |
||
42 |
class PlainSocketImpl extends AbstractPlainSocketImpl |
|
43 |
{ |
|
44 |
static { |
|
45 |
initProto(); |
|
46 |
} |
|
47 |
||
48 |
/** |
|
49 |
* Constructs an empty instance. |
|
50 |
*/ |
|
51 |
PlainSocketImpl() { } |
|
52 |
||
53 |
/** |
|
54 |
* Constructs an instance with the given file descriptor. |
|
55 |
*/ |
|
56 |
PlainSocketImpl(FileDescriptor fd) { |
|
57 |
this.fd = fd; |
|
58 |
} |
|
59 |
||
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
60 |
protected <T> void setOption(SocketOption<T> name, T value) throws IOException { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
61 |
if (!name.equals(ExtendedSocketOptions.SO_FLOW_SLA)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
62 |
super.setOption(name, value); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
63 |
} else { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
64 |
if (isClosedOrPending()) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
65 |
throw new SocketException("Socket closed"); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
66 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
67 |
checkSetOptionPermission(name); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
68 |
checkValueType(value, SocketFlow.class); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
69 |
setFlowOption(getFileDescriptor(), (SocketFlow)value); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
70 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
71 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
72 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
73 |
protected <T> T getOption(SocketOption<T> name) throws IOException { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
74 |
if (!name.equals(ExtendedSocketOptions.SO_FLOW_SLA)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
75 |
return super.getOption(name); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
76 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
77 |
if (isClosedOrPending()) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
78 |
throw new SocketException("Socket closed"); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
79 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
80 |
checkGetOptionPermission(name); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
81 |
SocketFlow flow = SocketFlow.create(); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
82 |
getFlowOption(getFileDescriptor(), flow); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
83 |
return (T)flow; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
84 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
85 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
86 |
protected Set<SocketOption<?>> supportedOptions() { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
87 |
HashSet<SocketOption<?>> options = new HashSet( |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
88 |
super.supportedOptions()); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
89 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
90 |
if (getSocket() != null && flowSupported()) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
91 |
options.add(ExtendedSocketOptions.SO_FLOW_SLA); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
92 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
93 |
return options; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
94 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
5506
diff
changeset
|
95 |
|
2 | 96 |
native void socketCreate(boolean isServer) throws IOException; |
97 |
||
98 |
native void socketConnect(InetAddress address, int port, int timeout) |
|
99 |
throws IOException; |
|
100 |
||
101 |
native void socketBind(InetAddress address, int port) |
|
102 |
throws IOException; |
|
103 |
||
104 |
native void socketListen(int count) throws IOException; |
|
105 |
||
106 |
native void socketAccept(SocketImpl s) throws IOException; |
|
107 |
||
108 |
native int socketAvailable() throws IOException; |
|
109 |
||
110 |
native void socketClose0(boolean useDeferredClose) throws IOException; |
|
111 |
||
112 |
native void socketShutdown(int howto) throws IOException; |
|
113 |
||
114 |
static native void initProto(); |
|
115 |
||
116 |
native void socketSetOption(int cmd, boolean on, Object value) |
|
117 |
throws SocketException; |
|
118 |
||
119 |
native int socketGetOption(int opt, Object iaContainerObj) throws SocketException; |
|
120 |
||
121 |
native void socketSendUrgentData(int data) throws IOException; |
|
122 |
} |