43 |
43 |
44 static final ExtendedSocketOptions extendedOptions = |
44 static final ExtendedSocketOptions extendedOptions = |
45 ExtendedSocketOptions.getInstance(); |
45 ExtendedSocketOptions.getInstance(); |
46 |
46 |
47 protected <T> void setOption(SocketOption<T> name, T value) throws IOException { |
47 protected <T> void setOption(SocketOption<T> name, T value) throws IOException { |
48 if (!extendedOptions.isOptionSupported(name)) { |
48 if (isClosed()) { |
49 if (!name.equals(StandardSocketOptions.SO_REUSEPORT)) { |
49 throw new SocketException("Socket closed"); |
|
50 } |
|
51 if (supportedOptions().contains(name)) { |
|
52 if (extendedOptions.isOptionSupported(name)) { |
|
53 extendedOptions.setOption(fd, name, value); |
|
54 } else { |
50 super.setOption(name, value); |
55 super.setOption(name, value); |
51 } else { |
|
52 if (supportedOptions().contains(name)) { |
|
53 super.setOption(name, value); |
|
54 } else { |
|
55 throw new UnsupportedOperationException("unsupported option"); |
|
56 } |
|
57 } |
56 } |
58 } else { |
57 } else { |
59 if (isClosed()) { |
58 throw new UnsupportedOperationException("unsupported option"); |
60 throw new SocketException("Socket closed"); |
|
61 } |
|
62 extendedOptions.setOption(fd, name, value); |
|
63 } |
59 } |
64 } |
60 } |
65 |
61 |
66 @SuppressWarnings("unchecked") |
62 @SuppressWarnings("unchecked") |
67 protected <T> T getOption(SocketOption<T> name) throws IOException { |
63 protected <T> T getOption(SocketOption<T> name) throws IOException { |
68 if (!extendedOptions.isOptionSupported(name)) { |
64 if (isClosed()) { |
69 if (!name.equals(StandardSocketOptions.SO_REUSEPORT)) { |
65 throw new SocketException("Socket closed"); |
|
66 } |
|
67 if (supportedOptions().contains(name)) { |
|
68 if (extendedOptions.isOptionSupported(name)) { |
|
69 return (T) extendedOptions.getOption(fd, name); |
|
70 } else { |
70 return super.getOption(name); |
71 return super.getOption(name); |
71 } else { |
|
72 if (supportedOptions().contains(name)) { |
|
73 return super.getOption(name); |
|
74 } else { |
|
75 throw new UnsupportedOperationException("unsupported option"); |
|
76 } |
|
77 } |
72 } |
78 } else { |
73 } else { |
79 if (isClosed()) { |
74 throw new UnsupportedOperationException("unsupported option"); |
80 throw new SocketException("Socket closed"); |
|
81 } |
|
82 return (T) extendedOptions.getOption(fd, name); |
|
83 } |
75 } |
84 } |
76 } |
85 |
77 |
86 protected Set<SocketOption<?>> supportedOptions() { |
78 protected Set<SocketOption<?>> supportedOptions() { |
87 HashSet<SocketOption<?>> options = new HashSet<>(super.supportedOptions()); |
79 HashSet<SocketOption<?>> options = new HashSet<>(super.supportedOptions()); |