37 |
37 |
38 class PlainDatagramSocketImpl extends AbstractPlainDatagramSocketImpl |
38 class PlainDatagramSocketImpl extends AbstractPlainDatagramSocketImpl |
39 { |
39 { |
40 static { |
40 static { |
41 init(); |
41 init(); |
42 } |
|
43 |
|
44 static final ExtendedSocketOptions extendedOptions = |
|
45 ExtendedSocketOptions.getInstance(); |
|
46 |
|
47 protected <T> void setOption(SocketOption<T> name, T value) throws IOException { |
|
48 if (isClosed()) { |
|
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 { |
|
55 super.setOption(name, value); |
|
56 } |
|
57 } else { |
|
58 throw new UnsupportedOperationException("unsupported option"); |
|
59 } |
|
60 } |
|
61 |
|
62 @SuppressWarnings("unchecked") |
|
63 protected <T> T getOption(SocketOption<T> name) throws IOException { |
|
64 if (isClosed()) { |
|
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 { |
|
71 return super.getOption(name); |
|
72 } |
|
73 } else { |
|
74 throw new UnsupportedOperationException("unsupported option"); |
|
75 } |
|
76 } |
|
77 |
|
78 protected Set<SocketOption<?>> supportedOptions() { |
|
79 HashSet<SocketOption<?>> options = new HashSet<>(super.supportedOptions()); |
|
80 options.addAll(ExtendedSocketOptions.datagramSocketOptions()); |
|
81 return options; |
|
82 } |
42 } |
83 |
43 |
84 protected void socketSetOption(int opt, Object val) throws SocketException { |
44 protected void socketSetOption(int opt, Object val) throws SocketException { |
85 if (opt == SocketOptions.SO_REUSEPORT && |
45 if (opt == SocketOptions.SO_REUSEPORT && |
86 !supportedOptions().contains(StandardSocketOptions.SO_REUSEPORT)) { |
46 !supportedOptions().contains(StandardSocketOptions.SO_REUSEPORT)) { |