23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 |
26 package jdk.internal.net.rdma; |
26 package jdk.internal.net.rdma; |
27 |
27 |
|
28 import sun.nio.ch.Net; |
|
29 |
28 import java.io.IOException; |
30 import java.io.IOException; |
29 import java.net.ProtocolFamily; |
31 import java.net.ProtocolFamily; |
|
32 import java.net.StandardProtocolFamily; |
30 import java.nio.channels.DatagramChannel; |
33 import java.nio.channels.DatagramChannel; |
31 import java.nio.channels.Pipe; |
34 import java.nio.channels.Pipe; |
32 import java.nio.channels.ServerSocketChannel; |
35 import java.nio.channels.ServerSocketChannel; |
33 import java.nio.channels.SocketChannel; |
36 import java.nio.channels.SocketChannel; |
34 import java.nio.channels.spi.AbstractSelector; |
37 import java.nio.channels.spi.AbstractSelector; |
35 import java.nio.channels.spi.SelectorProvider; |
38 import java.nio.channels.spi.SelectorProvider; |
36 import java.security.AccessController; |
39 |
37 import java.security.PrivilegedAction; |
40 import static java.net.StandardProtocolFamily.INET; |
|
41 import static java.net.StandardProtocolFamily.INET6; |
38 |
42 |
39 public class RdmaPollSelectorProvider |
43 public class RdmaPollSelectorProvider |
40 extends SelectorProvider |
44 extends SelectorProvider |
41 { |
45 { |
42 private static final Object lock = new Object(); |
46 private static final Object lock = new Object(); |
43 private static RdmaPollSelectorProvider provider; |
47 private static final RdmaPollSelectorProvider provider = |
|
48 new RdmaPollSelectorProvider(); |
44 |
49 |
45 public static RdmaPollSelectorProvider provider() { |
50 public static RdmaPollSelectorProvider provider() { |
46 synchronized (lock) { |
51 return provider; |
47 if (provider != null) |
|
48 return provider; |
|
49 return AccessController.doPrivileged( |
|
50 new PrivilegedAction<>() { |
|
51 public RdmaPollSelectorProvider run() { |
|
52 provider = new RdmaPollSelectorProvider(); |
|
53 return provider; |
|
54 } |
|
55 }); |
|
56 } |
|
57 } |
52 } |
58 |
53 |
59 @Override |
54 @Override |
60 public AbstractSelector openSelector() throws IOException { |
55 public AbstractSelector openSelector() throws IOException { |
61 return new RdmaPollSelectorImpl(this); |
56 return new RdmaPollSelectorImpl(this); |
62 } |
57 } |
63 |
58 |
64 @Override |
59 @Override |
65 public SocketChannel openSocketChannel() { |
60 public SocketChannel openSocketChannel() throws IOException { |
66 throw new UnsupportedOperationException(); |
61 if (Net.isIPv6Available()) { |
|
62 return openSocketChannel(INET6); |
|
63 } |
|
64 return openSocketChannel(INET); |
67 } |
65 } |
68 |
66 |
69 public SocketChannel openSocketChannel(ProtocolFamily family) |
67 public SocketChannel openSocketChannel(ProtocolFamily family) |
70 throws IOException |
68 throws IOException |
71 { |
69 { |
72 return new RdmaSocketChannelImpl(this, family); |
70 return new RdmaSocketChannelImpl(this, family); |
73 } |
71 } |
74 |
72 |
75 @Override |
73 @Override |
76 public ServerSocketChannel openServerSocketChannel() { |
74 public ServerSocketChannel openServerSocketChannel() throws IOException { |
77 throw new UnsupportedOperationException(); |
75 if (Net.isIPv6Available()) { |
|
76 return openServerSocketChannel(INET6); |
|
77 } |
|
78 return openServerSocketChannel(INET); |
78 } |
79 } |
79 |
80 |
80 public ServerSocketChannel openServerSocketChannel(ProtocolFamily family) |
81 public ServerSocketChannel openServerSocketChannel(ProtocolFamily family) |
81 throws IOException |
82 throws IOException |
82 { |
83 { |