equal
deleted
inserted
replaced
41 extends ServerSocket |
41 extends ServerSocket |
42 { |
42 { |
43 |
43 |
44 // The channel being adapted |
44 // The channel being adapted |
45 private final ServerSocketChannelImpl ssc; |
45 private final ServerSocketChannelImpl ssc; |
46 |
|
47 // Option adaptor object, created on demand |
|
48 private volatile OptionAdaptor opts = null; |
|
49 |
46 |
50 // Timeout "option" value for accepts |
47 // Timeout "option" value for accepts |
51 private volatile int timeout = 0; |
48 private volatile int timeout = 0; |
52 |
49 |
53 public static ServerSocket create(ServerSocketChannelImpl ssc) { |
50 public static ServerSocket create(ServerSocketChannelImpl ssc) { |
172 |
169 |
173 public int getSoTimeout() throws SocketException { |
170 public int getSoTimeout() throws SocketException { |
174 return timeout; |
171 return timeout; |
175 } |
172 } |
176 |
173 |
177 private OptionAdaptor opts() { |
|
178 if (opts == null) |
|
179 opts = new OptionAdaptor(ssc); |
|
180 return opts; |
|
181 } |
|
182 |
|
183 public void setReuseAddress(boolean on) throws SocketException { |
174 public void setReuseAddress(boolean on) throws SocketException { |
184 opts().setReuseAddress(on); |
175 try { |
|
176 ssc.setOption(StandardSocketOption.SO_REUSEADDR, on); |
|
177 } catch (IOException x) { |
|
178 Net.translateToSocketException(x); |
|
179 } |
185 } |
180 } |
186 |
181 |
187 public boolean getReuseAddress() throws SocketException { |
182 public boolean getReuseAddress() throws SocketException { |
188 return opts().getReuseAddress(); |
183 try { |
|
184 return ssc.getOption(StandardSocketOption.SO_REUSEADDR).booleanValue(); |
|
185 } catch (IOException x) { |
|
186 Net.translateToSocketException(x); |
|
187 return false; // Never happens |
|
188 } |
189 } |
189 } |
190 |
190 |
191 public String toString() { |
191 public String toString() { |
192 if (!isBound()) |
192 if (!isBound()) |
193 return "ServerSocket[unbound]"; |
193 return "ServerSocket[unbound]"; |
195 // ",port=" + getPort() + |
195 // ",port=" + getPort() + |
196 ",localport=" + getLocalPort() + "]"; |
196 ",localport=" + getLocalPort() + "]"; |
197 } |
197 } |
198 |
198 |
199 public void setReceiveBufferSize(int size) throws SocketException { |
199 public void setReceiveBufferSize(int size) throws SocketException { |
200 opts().setReceiveBufferSize(size); |
200 // size 0 valid for ServerSocketChannel, invalid for ServerSocket |
|
201 if (size <= 0) |
|
202 throw new IllegalArgumentException("size cannot be 0 or negative"); |
|
203 try { |
|
204 ssc.setOption(StandardSocketOption.SO_RCVBUF, size); |
|
205 } catch (IOException x) { |
|
206 Net.translateToSocketException(x); |
|
207 } |
201 } |
208 } |
202 |
209 |
203 public int getReceiveBufferSize() throws SocketException { |
210 public int getReceiveBufferSize() throws SocketException { |
204 return opts().getReceiveBufferSize(); |
211 try { |
|
212 return ssc.getOption(StandardSocketOption.SO_RCVBUF).intValue(); |
|
213 } catch (IOException x) { |
|
214 Net.translateToSocketException(x); |
|
215 return -1; // Never happens |
|
216 } |
205 } |
217 } |
206 |
218 |
207 } |
219 } |