jdk/src/java.base/share/classes/sun/nio/ch/AsynchronousServerSocketChannelImpl.java
equal
deleted
inserted
replaced
49 implements Cancellable, Groupable |
49 implements Cancellable, Groupable |
50 { |
50 { |
51 protected final FileDescriptor fd; |
51 protected final FileDescriptor fd; |
52 |
52 |
53 // the local address to which the channel's socket is bound |
53 // the local address to which the channel's socket is bound |
54 protected volatile InetSocketAddress localAddress = null; |
54 protected volatile InetSocketAddress localAddress; |
55 |
55 |
56 // need this lock to set local address |
56 // need this lock to set local address |
57 private final Object stateLock = new Object(); |
57 private final Object stateLock = new Object(); |
58 |
58 |
59 // close support |
59 // close support |
60 private ReadWriteLock closeLock = new ReentrantReadWriteLock(); |
60 private ReadWriteLock closeLock = new ReentrantReadWriteLock(); |
61 private volatile boolean open = true; |
61 private volatile boolean closed; |
62 |
62 |
63 // set true when accept operation is cancelled |
63 // set true when accept operation is cancelled |
64 private volatile boolean acceptKilled; |
64 private volatile boolean acceptKilled; |
65 |
65 |
66 // set true when exclusive binding is on and SO_REUSEADDR is emulated |
66 // set true when exclusive binding is on and SO_REUSEADDR is emulated |
71 this.fd = Net.serverSocket(true); |
71 this.fd = Net.serverSocket(true); |
72 } |
72 } |
73 |
73 |
74 @Override |
74 @Override |
75 public final boolean isOpen() { |
75 public final boolean isOpen() { |
76 return open; |
76 return !closed; |
77 } |
77 } |
78 |
78 |
79 /** |
79 /** |
80 * Marks beginning of access to file descriptor/handle |
80 * Marks beginning of access to file descriptor/handle |
81 */ |
81 */ |
100 @Override |
100 @Override |
101 public final void close() throws IOException { |
101 public final void close() throws IOException { |
102 // synchronize with any threads using file descriptor/handle |
102 // synchronize with any threads using file descriptor/handle |
103 closeLock.writeLock().lock(); |
103 closeLock.writeLock().lock(); |
104 try { |
104 try { |
105 if (!open) |
105 if (closed) |
106 return; // already closed |
106 return; // already closed |
107 open = false; |
107 closed = true; |
108 } finally { |
108 } finally { |
109 closeLock.writeLock().unlock(); |
109 closeLock.writeLock().unlock(); |
110 } |
110 } |
111 implClose(); |
111 implClose(); |
112 } |
112 } |