208 return DefaultOptionsHolder.defaultOptions; |
208 return DefaultOptionsHolder.defaultOptions; |
209 } |
209 } |
210 |
210 |
211 @Override |
211 @Override |
212 public ServerSocketChannel bind(SocketAddress local, int backlog) throws IOException { |
212 public ServerSocketChannel bind(SocketAddress local, int backlog) throws IOException { |
213 acceptLock.lock(); |
213 synchronized (stateLock) { |
214 try { |
214 ensureOpen(); |
215 synchronized (stateLock) { |
215 if (localAddress != null) |
216 ensureOpen(); |
216 throw new AlreadyBoundException(); |
217 if (localAddress != null) |
217 InetSocketAddress isa = (local == null) |
218 throw new AlreadyBoundException(); |
218 ? new InetSocketAddress(0) |
219 InetSocketAddress isa = (local == null) |
219 : Net.checkAddress(local); |
220 ? new InetSocketAddress(0) |
220 SecurityManager sm = System.getSecurityManager(); |
221 : Net.checkAddress(local); |
221 if (sm != null) |
222 SecurityManager sm = System.getSecurityManager(); |
222 sm.checkListen(isa.getPort()); |
223 if (sm != null) |
223 NetHooks.beforeTcpBind(fd, isa.getAddress(), isa.getPort()); |
224 sm.checkListen(isa.getPort()); |
224 Net.bind(fd, isa.getAddress(), isa.getPort()); |
225 NetHooks.beforeTcpBind(fd, isa.getAddress(), isa.getPort()); |
225 Net.listen(fd, backlog < 1 ? 50 : backlog); |
226 Net.bind(fd, isa.getAddress(), isa.getPort()); |
226 localAddress = Net.localAddress(fd); |
227 Net.listen(fd, backlog < 1 ? 50 : backlog); |
|
228 localAddress = Net.localAddress(fd); |
|
229 } |
|
230 } finally { |
|
231 acceptLock.unlock(); |
|
232 } |
227 } |
233 return this; |
228 return this; |
234 } |
229 } |
235 |
230 |
236 /** |
231 /** |