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.DefaultServerSocketChannelConfig;
24 import io.netty.channel.socket.ServerSocketChannel;
25
26 import java.io.IOException;
27 import java.net.ServerSocket;
28 import java.util.Map;
29
30 import static io.netty.channel.ChannelOption.*;
31
32
33
34
35 public class DefaultOioServerSocketChannelConfig extends DefaultServerSocketChannelConfig implements
36 OioServerSocketChannelConfig {
37
38 @Deprecated
39 public DefaultOioServerSocketChannelConfig(ServerSocketChannel channel, ServerSocket javaSocket) {
40 super(channel, javaSocket);
41 }
42
43 DefaultOioServerSocketChannelConfig(OioServerSocketChannel channel, ServerSocket javaSocket) {
44 super(channel, javaSocket);
45 }
46
47 @Override
48 public Map<ChannelOption<?>, Object> getOptions() {
49 return getOptions(
50 super.getOptions(), SO_TIMEOUT);
51 }
52
53 @SuppressWarnings("unchecked")
54 @Override
55 public <T> T getOption(ChannelOption<T> option) {
56 if (option == SO_TIMEOUT) {
57 return (T) Integer.valueOf(getSoTimeout());
58 }
59 return super.getOption(option);
60 }
61
62 @Override
63 public <T> boolean setOption(ChannelOption<T> option, T value) {
64 validate(option, value);
65
66 if (option == SO_TIMEOUT) {
67 setSoTimeout((Integer) value);
68 } else {
69 return super.setOption(option, value);
70 }
71 return true;
72 }
73
74 @Override
75 public OioServerSocketChannelConfig setSoTimeout(int timeout) {
76 try {
77 javaSocket.setSoTimeout(timeout);
78 } catch (IOException e) {
79 throw new ChannelException(e);
80 }
81 return this;
82 }
83
84 @Override
85 public int getSoTimeout() {
86 try {
87 return javaSocket.getSoTimeout();
88 } catch (IOException e) {
89 throw new ChannelException(e);
90 }
91 }
92
93 @Override
94 public OioServerSocketChannelConfig setBacklog(int backlog) {
95 super.setBacklog(backlog);
96 return this;
97 }
98
99 @Override
100 public OioServerSocketChannelConfig setReuseAddress(boolean reuseAddress) {
101 super.setReuseAddress(reuseAddress);
102 return this;
103 }
104
105 @Override
106 public OioServerSocketChannelConfig setReceiveBufferSize(int receiveBufferSize) {
107 super.setReceiveBufferSize(receiveBufferSize);
108 return this;
109 }
110
111 @Override
112 public OioServerSocketChannelConfig setPerformancePreferences(int connectionTime, int latency, int bandwidth) {
113 super.setPerformancePreferences(connectionTime, latency, bandwidth);
114 return this;
115 }
116
117 @Override
118 public OioServerSocketChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis) {
119 super.setConnectTimeoutMillis(connectTimeoutMillis);
120 return this;
121 }
122
123 @Override
124 public OioServerSocketChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead) {
125 super.setMaxMessagesPerRead(maxMessagesPerRead);
126 return this;
127 }
128
129 @Override
130 public OioServerSocketChannelConfig setWriteSpinCount(int writeSpinCount) {
131 super.setWriteSpinCount(writeSpinCount);
132 return this;
133 }
134
135 @Override
136 public OioServerSocketChannelConfig setAllocator(ByteBufAllocator allocator) {
137 super.setAllocator(allocator);
138 return this;
139 }
140
141 @Override
142 public OioServerSocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) {
143 super.setRecvByteBufAllocator(allocator);
144 return this;
145 }
146
147 @Override
148 public OioServerSocketChannelConfig setAutoRead(boolean autoRead) {
149 super.setAutoRead(autoRead);
150 return this;
151 }
152
153 @Override
154 protected void autoReadCleared() {
155 if (channel instanceof OioServerSocketChannel) {
156 ((OioServerSocketChannel) channel).setReadPending(false);
157 }
158 }
159
160 @Override
161 public OioServerSocketChannelConfig setAutoClose(boolean autoClose) {
162 super.setAutoClose(autoClose);
163 return this;
164 }
165
166 @Override
167 public OioServerSocketChannelConfig setWriteBufferHighWaterMark(int writeBufferHighWaterMark) {
168 super.setWriteBufferHighWaterMark(writeBufferHighWaterMark);
169 return this;
170 }
171
172 @Override
173 public OioServerSocketChannelConfig setWriteBufferLowWaterMark(int writeBufferLowWaterMark) {
174 super.setWriteBufferLowWaterMark(writeBufferLowWaterMark);
175 return this;
176 }
177
178 @Override
179 public OioServerSocketChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimator) {
180 super.setMessageSizeEstimator(estimator);
181 return this;
182 }
183 }