22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.nio.ch;
27
28 import java.nio.ByteBuffer;
29 import java.nio.channels.*;
30 import java.net.SocketOption;
31 import java.net.StandardSocketOptions;
32 import java.net.SocketAddress;
33 import java.net.InetSocketAddress;
34 import java.io.IOException;
35 import java.io.FileDescriptor;
36 import java.util.Set;
37 import java.util.HashSet;
38 import java.util.Collections;
39 import java.util.concurrent.*;
40 import java.util.concurrent.locks.*;
41 import sun.net.NetHooks;
42
43 /**
44 * Base implementation of AsynchronousSocketChannel
45 */
46
47 abstract class AsynchronousSocketChannelImpl
48 extends AsynchronousSocketChannel
49 implements Cancellable, Groupable
50 {
51 protected final FileDescriptor fd;
52
53 // protects state, localAddress, and remoteAddress
54 protected final Object stateLock = new Object();
55
56 protected volatile InetSocketAddress localAddress = null;
57 protected volatile InetSocketAddress remoteAddress = null;
58
59 // State, increases monotonically
60 static final int ST_UNINITIALIZED = -1;
61 static final int ST_UNCONNECTED = 0;
491 {
492 // SO_REUSEADDR emulated when using exclusive bind
493 return (T)Boolean.valueOf(isReuseAddress);
494 }
495 return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
496 } finally {
497 end();
498 }
499 }
500
501 private static class DefaultOptionsHolder {
502 static final Set<SocketOption<?>> defaultOptions = defaultOptions();
503
504 private static Set<SocketOption<?>> defaultOptions() {
505 HashSet<SocketOption<?>> set = new HashSet<SocketOption<?>>(5);
506 set.add(StandardSocketOptions.SO_SNDBUF);
507 set.add(StandardSocketOptions.SO_RCVBUF);
508 set.add(StandardSocketOptions.SO_KEEPALIVE);
509 set.add(StandardSocketOptions.SO_REUSEADDR);
510 set.add(StandardSocketOptions.TCP_NODELAY);
511 return Collections.unmodifiableSet(set);
512 }
513 }
514
515 @Override
516 public final Set<SocketOption<?>> supportedOptions() {
517 return DefaultOptionsHolder.defaultOptions;
518 }
519
520 @Override
521 public final SocketAddress getRemoteAddress() throws IOException {
522 if (!isOpen())
523 throw new ClosedChannelException();
524 return remoteAddress;
525 }
526
527 @Override
528 public final AsynchronousSocketChannel shutdownInput() throws IOException {
529 try {
530 begin();
|
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.nio.ch;
27
28 import java.nio.ByteBuffer;
29 import java.nio.channels.*;
30 import java.net.SocketOption;
31 import java.net.StandardSocketOptions;
32 import java.net.SocketAddress;
33 import java.net.InetSocketAddress;
34 import java.io.IOException;
35 import java.io.FileDescriptor;
36 import java.util.Set;
37 import java.util.HashSet;
38 import java.util.Collections;
39 import java.util.concurrent.*;
40 import java.util.concurrent.locks.*;
41 import sun.net.NetHooks;
42 import sun.net.ExtendedOptionsImpl;
43
44 /**
45 * Base implementation of AsynchronousSocketChannel
46 */
47
48 abstract class AsynchronousSocketChannelImpl
49 extends AsynchronousSocketChannel
50 implements Cancellable, Groupable
51 {
52 protected final FileDescriptor fd;
53
54 // protects state, localAddress, and remoteAddress
55 protected final Object stateLock = new Object();
56
57 protected volatile InetSocketAddress localAddress = null;
58 protected volatile InetSocketAddress remoteAddress = null;
59
60 // State, increases monotonically
61 static final int ST_UNINITIALIZED = -1;
62 static final int ST_UNCONNECTED = 0;
492 {
493 // SO_REUSEADDR emulated when using exclusive bind
494 return (T)Boolean.valueOf(isReuseAddress);
495 }
496 return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
497 } finally {
498 end();
499 }
500 }
501
502 private static class DefaultOptionsHolder {
503 static final Set<SocketOption<?>> defaultOptions = defaultOptions();
504
505 private static Set<SocketOption<?>> defaultOptions() {
506 HashSet<SocketOption<?>> set = new HashSet<SocketOption<?>>(5);
507 set.add(StandardSocketOptions.SO_SNDBUF);
508 set.add(StandardSocketOptions.SO_RCVBUF);
509 set.add(StandardSocketOptions.SO_KEEPALIVE);
510 set.add(StandardSocketOptions.SO_REUSEADDR);
511 set.add(StandardSocketOptions.TCP_NODELAY);
512 if (ExtendedOptionsImpl.flowSupported()) {
513 set.add(jdk.net.ExtendedSocketOptions.SO_FLOW_SLA);
514 }
515 return Collections.unmodifiableSet(set);
516 }
517 }
518
519 @Override
520 public final Set<SocketOption<?>> supportedOptions() {
521 return DefaultOptionsHolder.defaultOptions;
522 }
523
524 @Override
525 public final SocketAddress getRemoteAddress() throws IOException {
526 if (!isOpen())
527 throw new ClosedChannelException();
528 return remoteAddress;
529 }
530
531 @Override
532 public final AsynchronousSocketChannel shutdownInput() throws IOException {
533 try {
534 begin();
|