45 /** |
44 /** |
46 * Constructs an empty instance. |
45 * Constructs an empty instance. |
47 */ |
46 */ |
48 PlainSocketImpl(boolean isServer) { |
47 PlainSocketImpl(boolean isServer) { |
49 super(isServer); |
48 super(isServer); |
50 } |
|
51 |
|
52 static final ExtendedSocketOptions extendedOptions = |
|
53 ExtendedSocketOptions.getInstance(); |
|
54 |
|
55 protected <T> void setOption(SocketOption<T> name, T value) throws IOException { |
|
56 if (isClosedOrPending()) { |
|
57 throw new SocketException("Socket closed"); |
|
58 } |
|
59 if (supportedOptions().contains(name)) { |
|
60 if (extendedOptions.isOptionSupported(name)) { |
|
61 extendedOptions.setOption(fd, name, value); |
|
62 } else { |
|
63 super.setOption(name, value); |
|
64 } |
|
65 } else { |
|
66 throw new UnsupportedOperationException("unsupported option"); |
|
67 } |
|
68 } |
|
69 |
|
70 @SuppressWarnings("unchecked") |
|
71 protected <T> T getOption(SocketOption<T> name) throws IOException { |
|
72 if (isClosedOrPending()) { |
|
73 throw new SocketException("Socket closed"); |
|
74 } |
|
75 if (supportedOptions().contains(name)) { |
|
76 if (extendedOptions.isOptionSupported(name)) { |
|
77 return (T) extendedOptions.getOption(fd, name); |
|
78 } else { |
|
79 return super.getOption(name); |
|
80 } |
|
81 } else { |
|
82 throw new UnsupportedOperationException("unsupported option"); |
|
83 } |
|
84 } |
|
85 |
|
86 protected Set<SocketOption<?>> supportedOptions() { |
|
87 HashSet<SocketOption<?>> options = new HashSet<>(super.supportedOptions()); |
|
88 if (isServer) { |
|
89 options.addAll(ExtendedSocketOptions.serverSocketOptions()); |
|
90 } else { |
|
91 options.addAll(ExtendedSocketOptions.clientSocketOptions()); |
|
92 } |
|
93 return options; |
|
94 } |
49 } |
95 |
50 |
96 protected void socketSetOption(int opt, boolean b, Object val) throws SocketException { |
51 protected void socketSetOption(int opt, boolean b, Object val) throws SocketException { |
97 if (opt == SocketOptions.SO_REUSEPORT && |
52 if (opt == SocketOptions.SO_REUSEPORT && |
98 !supportedOptions().contains(StandardSocketOptions.SO_REUSEPORT)) { |
53 !supportedOptions().contains(StandardSocketOptions.SO_REUSEPORT)) { |