30 import java.net.*; |
30 import java.net.*; |
31 import java.util.concurrent.*; |
31 import java.util.concurrent.*; |
32 import java.io.IOException; |
32 import java.io.IOException; |
33 import java.io.FileDescriptor; |
33 import java.io.FileDescriptor; |
34 import java.security.AccessController; |
34 import java.security.AccessController; |
|
35 import sun.net.NetHooks; |
35 import sun.security.action.GetPropertyAction; |
36 import sun.security.action.GetPropertyAction; |
36 |
37 |
37 /** |
38 /** |
38 * Unix implementation of AsynchronousSocketChannel |
39 * Unix implementation of AsynchronousSocketChannel |
39 */ |
40 */ |
303 SecurityManager sm = System.getSecurityManager(); |
304 SecurityManager sm = System.getSecurityManager(); |
304 if (sm != null) |
305 if (sm != null) |
305 sm.checkConnect(isa.getAddress().getHostAddress(), isa.getPort()); |
306 sm.checkConnect(isa.getAddress().getHostAddress(), isa.getPort()); |
306 |
307 |
307 // check and set state |
308 // check and set state |
|
309 boolean notifyBeforeTcpConnect; |
308 synchronized (stateLock) { |
310 synchronized (stateLock) { |
309 if (state == ST_CONNECTED) |
311 if (state == ST_CONNECTED) |
310 throw new AlreadyConnectedException(); |
312 throw new AlreadyConnectedException(); |
311 if (state == ST_PENDING) |
313 if (state == ST_PENDING) |
312 throw new ConnectionPendingException(); |
314 throw new ConnectionPendingException(); |
313 state = ST_PENDING; |
315 state = ST_PENDING; |
314 pendingRemote = remote; |
316 pendingRemote = remote; |
|
317 notifyBeforeTcpConnect = (localAddress == null); |
315 } |
318 } |
316 |
319 |
317 AbstractFuture<Void,A> result = null; |
320 AbstractFuture<Void,A> result = null; |
318 Throwable e = null; |
321 Throwable e = null; |
319 try { |
322 try { |
320 begin(); |
323 begin(); |
|
324 // notify hook if unbound |
|
325 if (notifyBeforeTcpConnect) |
|
326 NetHooks.beforeTcpConnect(fd, isa.getAddress(), isa.getPort()); |
321 int n = Net.connect(fd, isa.getAddress(), isa.getPort()); |
327 int n = Net.connect(fd, isa.getAddress(), isa.getPort()); |
322 if (n == IOStatus.UNAVAILABLE) { |
328 if (n == IOStatus.UNAVAILABLE) { |
323 // connection could not be established immediately |
329 // connection could not be established immediately |
324 result = new PendingFuture<Void,A>(this, handler, attachment, OpType.CONNECT); |
330 result = new PendingFuture<Void,A>(this, handler, attachment, OpType.CONNECT); |
325 synchronized (updateLock) { |
331 synchronized (updateLock) { |