equal
deleted
inserted
replaced
70 private static final int ST_INUSE = 0; |
70 private static final int ST_INUSE = 0; |
71 private static final int ST_KILLED = 1; |
71 private static final int ST_KILLED = 1; |
72 private int state = ST_UNINITIALIZED; |
72 private int state = ST_UNINITIALIZED; |
73 |
73 |
74 // Binding |
74 // Binding |
75 private SocketAddress localAddress; // null => unbound |
75 private InetSocketAddress localAddress; // null => unbound |
76 |
76 |
77 // set true when exclusive binding is on and SO_REUSEADDR is emulated |
77 // set true when exclusive binding is on and SO_REUSEADDR is emulated |
78 private boolean isReuseAddress; |
78 private boolean isReuseAddress; |
79 |
79 |
80 // Our socket adaptor, if any |
80 // Our socket adaptor, if any |
114 @Override |
114 @Override |
115 public SocketAddress getLocalAddress() throws IOException { |
115 public SocketAddress getLocalAddress() throws IOException { |
116 synchronized (stateLock) { |
116 synchronized (stateLock) { |
117 if (!isOpen()) |
117 if (!isOpen()) |
118 throw new ClosedChannelException(); |
118 throw new ClosedChannelException(); |
119 return localAddress; |
119 return localAddress == null ? localAddress |
|
120 : Net.getRevealedLocalAddress( |
|
121 Net.asInetSocketAddress(localAddress)); |
120 } |
122 } |
121 } |
123 } |
122 |
124 |
123 @Override |
125 @Override |
124 public <T> ServerSocketChannel setOption(SocketOption<T> name, T value) |
126 public <T> ServerSocketChannel setOption(SocketOption<T> name, T value) |
188 synchronized (stateLock) { |
190 synchronized (stateLock) { |
189 return localAddress != null; |
191 return localAddress != null; |
190 } |
192 } |
191 } |
193 } |
192 |
194 |
193 public SocketAddress localAddress() { |
195 public InetSocketAddress localAddress() { |
194 synchronized (stateLock) { |
196 synchronized (stateLock) { |
195 return localAddress; |
197 return localAddress; |
196 } |
198 } |
197 } |
199 } |
198 |
200 |
382 |
384 |
383 public String toString() { |
385 public String toString() { |
384 StringBuffer sb = new StringBuffer(); |
386 StringBuffer sb = new StringBuffer(); |
385 sb.append(this.getClass().getName()); |
387 sb.append(this.getClass().getName()); |
386 sb.append('['); |
388 sb.append('['); |
387 if (!isOpen()) |
389 if (!isOpen()) { |
388 sb.append("closed"); |
390 sb.append("closed"); |
389 else { |
391 } else { |
390 synchronized (stateLock) { |
392 synchronized (stateLock) { |
391 if (localAddress() == null) { |
393 InetSocketAddress addr = localAddress(); |
|
394 if (addr == null) { |
392 sb.append("unbound"); |
395 sb.append("unbound"); |
393 } else { |
396 } else { |
394 sb.append(localAddress().toString()); |
397 sb.append(Net.getRevealedLocalAddressAsString(addr)); |
395 } |
398 } |
396 } |
399 } |
397 } |
400 } |
398 sb.append(']'); |
401 sb.append(']'); |
399 return sb.toString(); |
402 return sb.toString(); |