1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel.epoll;
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.WriteBufferWaterMark;
24 import io.netty.channel.socket.ServerSocketChannelConfig;
25
26 import java.io.IOException;
27 import java.net.InetAddress;
28 import java.util.Map;
29
30 public final class EpollServerSocketChannelConfig extends EpollServerChannelConfig
31 implements ServerSocketChannelConfig {
32
33 EpollServerSocketChannelConfig(EpollServerSocketChannel channel) {
34 super(channel);
35
36
37
38
39 setReuseAddress(true);
40 }
41
42 @Override
43 public Map<ChannelOption<?>, Object> getOptions() {
44 return getOptions(super.getOptions(), EpollChannelOption.SO_REUSEPORT, EpollChannelOption.IP_FREEBIND,
45 EpollChannelOption.IP_TRANSPARENT, EpollChannelOption.TCP_DEFER_ACCEPT);
46 }
47
48 @SuppressWarnings("unchecked")
49 @Override
50 public <T> T getOption(ChannelOption<T> option) {
51 if (option == EpollChannelOption.SO_REUSEPORT) {
52 return (T) Boolean.valueOf(isReusePort());
53 }
54 if (option == EpollChannelOption.IP_FREEBIND) {
55 return (T) Boolean.valueOf(isFreeBind());
56 }
57 if (option == EpollChannelOption.IP_TRANSPARENT) {
58 return (T) Boolean.valueOf(isIpTransparent());
59 }
60 if (option == EpollChannelOption.TCP_DEFER_ACCEPT) {
61 return (T) Integer.valueOf(getTcpDeferAccept());
62 }
63 return super.getOption(option);
64 }
65
66 @Override
67 public <T> boolean setOption(ChannelOption<T> option, T value) {
68 validate(option, value);
69
70 if (option == EpollChannelOption.SO_REUSEPORT) {
71 setReusePort((Boolean) value);
72 } else if (option == EpollChannelOption.IP_FREEBIND) {
73 setFreeBind((Boolean) value);
74 } else if (option == EpollChannelOption.IP_TRANSPARENT) {
75 setIpTransparent((Boolean) value);
76 } else if (option == EpollChannelOption.TCP_MD5SIG) {
77 @SuppressWarnings("unchecked")
78 final Map<InetAddress, byte[]> m = (Map<InetAddress, byte[]>) value;
79 setTcpMd5Sig(m);
80 } else if (option == EpollChannelOption.TCP_DEFER_ACCEPT) {
81 setTcpDeferAccept((Integer) value);
82 } else {
83 return super.setOption(option, value);
84 }
85
86 return true;
87 }
88
89 @Override
90 public EpollServerSocketChannelConfig setReuseAddress(boolean reuseAddress) {
91 super.setReuseAddress(reuseAddress);
92 return this;
93 }
94
95 @Override
96 public EpollServerSocketChannelConfig setReceiveBufferSize(int receiveBufferSize) {
97 super.setReceiveBufferSize(receiveBufferSize);
98 return this;
99 }
100
101 @Override
102 public EpollServerSocketChannelConfig setPerformancePreferences(int connectionTime, int latency, int bandwidth) {
103 return this;
104 }
105
106 @Override
107 public EpollServerSocketChannelConfig setBacklog(int backlog) {
108 super.setBacklog(backlog);
109 return this;
110 }
111
112 @Override
113 public EpollServerSocketChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis) {
114 super.setConnectTimeoutMillis(connectTimeoutMillis);
115 return this;
116 }
117
118 @Override
119 @Deprecated
120 public EpollServerSocketChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead) {
121 super.setMaxMessagesPerRead(maxMessagesPerRead);
122 return this;
123 }
124
125 @Override
126 public EpollServerSocketChannelConfig setWriteSpinCount(int writeSpinCount) {
127 super.setWriteSpinCount(writeSpinCount);
128 return this;
129 }
130
131 @Override
132 public EpollServerSocketChannelConfig setAllocator(ByteBufAllocator allocator) {
133 super.setAllocator(allocator);
134 return this;
135 }
136
137 @Override
138 public EpollServerSocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) {
139 super.setRecvByteBufAllocator(allocator);
140 return this;
141 }
142
143 @Override
144 public EpollServerSocketChannelConfig setAutoRead(boolean autoRead) {
145 super.setAutoRead(autoRead);
146 return this;
147 }
148
149 @Override
150 @Deprecated
151 public EpollServerSocketChannelConfig setWriteBufferHighWaterMark(int writeBufferHighWaterMark) {
152 super.setWriteBufferHighWaterMark(writeBufferHighWaterMark);
153 return this;
154 }
155
156 @Override
157 @Deprecated
158 public EpollServerSocketChannelConfig setWriteBufferLowWaterMark(int writeBufferLowWaterMark) {
159 super.setWriteBufferLowWaterMark(writeBufferLowWaterMark);
160 return this;
161 }
162
163 @Override
164 public EpollServerSocketChannelConfig setWriteBufferWaterMark(WriteBufferWaterMark writeBufferWaterMark) {
165 super.setWriteBufferWaterMark(writeBufferWaterMark);
166 return this;
167 }
168
169 @Override
170 public EpollServerSocketChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimator) {
171 super.setMessageSizeEstimator(estimator);
172 return this;
173 }
174
175
176
177
178
179
180 public EpollServerSocketChannelConfig setTcpMd5Sig(Map<InetAddress, byte[]> keys) {
181 try {
182 ((EpollServerSocketChannel) channel).setTcpMd5Sig(keys);
183 return this;
184 } catch (IOException e) {
185 throw new ChannelException(e);
186 }
187 }
188
189
190
191
192 public boolean isReusePort() {
193 try {
194 return ((EpollServerSocketChannel) channel).socket.isReusePort();
195 } catch (IOException e) {
196 throw new ChannelException(e);
197 }
198 }
199
200
201
202
203
204
205
206
207 public EpollServerSocketChannelConfig setReusePort(boolean reusePort) {
208 try {
209 ((EpollServerSocketChannel) channel).socket.setReusePort(reusePort);
210 return this;
211 } catch (IOException e) {
212 throw new ChannelException(e);
213 }
214 }
215
216
217
218
219
220 public boolean isFreeBind() {
221 try {
222 return ((EpollServerSocketChannel) channel).socket.isIpFreeBind();
223 } catch (IOException e) {
224 throw new ChannelException(e);
225 }
226 }
227
228
229
230
231
232 public EpollServerSocketChannelConfig setFreeBind(boolean freeBind) {
233 try {
234 ((EpollServerSocketChannel) channel).socket.setIpFreeBind(freeBind);
235 return this;
236 } catch (IOException e) {
237 throw new ChannelException(e);
238 }
239 }
240
241
242
243
244
245 public boolean isIpTransparent() {
246 try {
247 return ((EpollServerSocketChannel) channel).socket.isIpTransparent();
248 } catch (IOException e) {
249 throw new ChannelException(e);
250 }
251 }
252
253
254
255
256
257 public EpollServerSocketChannelConfig setIpTransparent(boolean transparent) {
258 try {
259 ((EpollServerSocketChannel) channel).socket.setIpTransparent(transparent);
260 return this;
261 } catch (IOException e) {
262 throw new ChannelException(e);
263 }
264 }
265
266
267
268
269 public EpollServerSocketChannelConfig setTcpDeferAccept(int deferAccept) {
270 try {
271 ((EpollServerSocketChannel) channel).socket.setTcpDeferAccept(deferAccept);
272 return this;
273 } catch (IOException e) {
274 throw new ChannelException(e);
275 }
276 }
277
278
279
280
281 public int getTcpDeferAccept() {
282 try {
283 return ((EpollServerSocketChannel) channel).socket.getTcpDeferAccept();
284 } catch (IOException e) {
285 throw new ChannelException(e);
286 }
287 }
288 }