1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel.socket.oio;
17
18 import io.netty.buffer.ByteBufAllocator;
19 import io.netty.channel.ChannelException;
20 import io.netty.channel.ChannelOption;
21 import io.netty.channel.MessageSizeEstimator;
22 import io.netty.channel.RecvByteBufAllocator;
23 import io.netty.channel.socket.DatagramChannel;
24 import io.netty.channel.socket.DefaultDatagramChannelConfig;
25
26 import java.io.IOException;
27 import java.net.DatagramSocket;
28 import java.net.InetAddress;
29 import java.net.NetworkInterface;
30 import java.util.Map;
31
32 import static io.netty.channel.ChannelOption.SO_TIMEOUT;
33
34 final class DefaultOioDatagramChannelConfig extends DefaultDatagramChannelConfig implements OioDatagramChannelConfig {
35
36 DefaultOioDatagramChannelConfig(DatagramChannel channel, DatagramSocket javaSocket) {
37 super(channel, javaSocket);
38 }
39
40 @Override
41 public Map<ChannelOption<?>, Object> getOptions() {
42 return getOptions(super.getOptions(), SO_TIMEOUT);
43 }
44
45 @SuppressWarnings("unchecked")
46 @Override
47 public <T> T getOption(ChannelOption<T> option) {
48 if (option == SO_TIMEOUT) {
49 return (T) Integer.valueOf(getSoTimeout());
50 }
51 return super.getOption(option);
52 }
53
54 @Override
55 public <T> boolean setOption(ChannelOption<T> option, T value) {
56 validate(option, value);
57
58 if (option == SO_TIMEOUT) {
59 setSoTimeout((Integer) value);
60 } else {
61 return super.setOption(option, value);
62 }
63 return true;
64 }
65
66 @Override
67 public OioDatagramChannelConfig setSoTimeout(int timeout) {
68 try {
69 javaSocket().setSoTimeout(timeout);
70 } catch (IOException e) {
71 throw new ChannelException(e);
72 }
73 return this;
74 }
75
76 @Override
77 public int getSoTimeout() {
78 try {
79 return javaSocket().getSoTimeout();
80 } catch (IOException e) {
81 throw new ChannelException(e);
82 }
83 }
84
85 @Override
86 public OioDatagramChannelConfig setBroadcast(boolean broadcast) {
87 super.setBroadcast(broadcast);
88 return this;
89 }
90
91 @Override
92 public OioDatagramChannelConfig setInterface(InetAddress interfaceAddress) {
93 super.setInterface(interfaceAddress);
94 return this;
95 }
96
97 @Override
98 public OioDatagramChannelConfig setLoopbackModeDisabled(boolean loopbackModeDisabled) {
99 super.setLoopbackModeDisabled(loopbackModeDisabled);
100 return this;
101 }
102
103 @Override
104 public OioDatagramChannelConfig setNetworkInterface(NetworkInterface networkInterface) {
105 super.setNetworkInterface(networkInterface);
106 return this;
107 }
108
109 @Override
110 public OioDatagramChannelConfig setReuseAddress(boolean reuseAddress) {
111 super.setReuseAddress(reuseAddress);
112 return this;
113 }
114
115 @Override
116 public OioDatagramChannelConfig setReceiveBufferSize(int receiveBufferSize) {
117 super.setReceiveBufferSize(receiveBufferSize);
118 return this;
119 }
120
121 @Override
122 public OioDatagramChannelConfig setSendBufferSize(int sendBufferSize) {
123 super.setSendBufferSize(sendBufferSize);
124 return this;
125 }
126
127 @Override
128 public OioDatagramChannelConfig setTimeToLive(int ttl) {
129 super.setTimeToLive(ttl);
130 return this;
131 }
132
133 @Override
134 public OioDatagramChannelConfig setTrafficClass(int trafficClass) {
135 super.setTrafficClass(trafficClass);
136 return this;
137 }
138
139 @Override
140 public OioDatagramChannelConfig setWriteSpinCount(int writeSpinCount) {
141 super.setWriteSpinCount(writeSpinCount);
142 return this;
143 }
144
145 @Override
146 public OioDatagramChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis) {
147 super.setConnectTimeoutMillis(connectTimeoutMillis);
148 return this;
149 }
150
151 @Override
152 public OioDatagramChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead) {
153 super.setMaxMessagesPerRead(maxMessagesPerRead);
154 return this;
155 }
156
157 @Override
158 public OioDatagramChannelConfig setAllocator(ByteBufAllocator allocator) {
159 super.setAllocator(allocator);
160 return this;
161 }
162
163 @Override
164 public OioDatagramChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) {
165 super.setRecvByteBufAllocator(allocator);
166 return this;
167 }
168
169 @Override
170 public OioDatagramChannelConfig setAutoRead(boolean autoRead) {
171 super.setAutoRead(autoRead);
172 return this;
173 }
174
175 @Override
176 public OioDatagramChannelConfig setAutoClose(boolean autoClose) {
177 super.setAutoClose(autoClose);
178 return this;
179 }
180
181 @Override
182 public OioDatagramChannelConfig setWriteBufferHighWaterMark(int writeBufferHighWaterMark) {
183 super.setWriteBufferHighWaterMark(writeBufferHighWaterMark);
184 return this;
185 }
186
187 @Override
188 public OioDatagramChannelConfig setWriteBufferLowWaterMark(int writeBufferLowWaterMark) {
189 super.setWriteBufferLowWaterMark(writeBufferLowWaterMark);
190 return this;
191 }
192
193 @Override
194 public OioDatagramChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimator) {
195 super.setMessageSizeEstimator(estimator);
196 return this;
197 }
198 }