< prev index next >
src/jdk.net/linux/classes/jdk/internal/net/rdma/RdmaSocketImpl.java
Print this page
rev 52804 : [mq]: nullBinding
rev 52801 : imported patch jdk12-8195160-version23.patch
*** 23,60 ****
* questions.
*/
package jdk.internal.net.rdma;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
- import java.io.FileDescriptor;
- import java.lang.reflect.Field;
- import java.net.InetAddress;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.ProtocolFamily;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketImpl;
import java.net.SocketOption;
- import java.net.SocketException;
- import java.net.StandardProtocolFamily;
- import java.net.UnknownHostException;
- import java.net.InetAddress;
- import java.net.SocketAddress;
- import java.net.InetSocketAddress;
- import java.net.StandardSocketOptions;
import java.net.SocketOptions;
! import java.security.AccessController;
! import java.security.PrivilegedAction;
import java.util.Objects;
import java.util.Set;
import sun.nio.ch.Net;
! import sun.net.ConnectionResetException;
! import sun.net.ext.RdmaSocketOptions;
public abstract class RdmaSocketImpl extends SocketImpl
{
private ProtocolFamily family;
--- 23,55 ----
* questions.
*/
package jdk.internal.net.rdma;
+ import java.io.FileDescriptor;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Inet4Address;
import java.net.Inet6Address;
+ import java.net.InetAddress;
+ import java.net.InetSocketAddress;
import java.net.ProtocolFamily;
import java.net.ServerSocket;
import java.net.Socket;
+ import java.net.SocketAddress;
+ import java.net.SocketException;
import java.net.SocketImpl;
import java.net.SocketOption;
import java.net.SocketOptions;
! import java.net.StandardSocketOptions;
! import java.net.UnknownHostException;
import java.util.Objects;
import java.util.Set;
import sun.nio.ch.Net;
! import static java.net.StandardProtocolFamily.INET;
! import static java.net.StandardProtocolFamily.INET6;
public abstract class RdmaSocketImpl extends SocketImpl
{
private ProtocolFamily family;
*** 120,147 ****
return null;
}
}
public RdmaSocketImpl(ProtocolFamily family) {
! this(checkSupported());
! Objects.requireNonNull(family, "'family' is null");
! if ((family != StandardProtocolFamily.INET) &&
! (family != StandardProtocolFamily.INET6)) {
! throw new UnsupportedOperationException(
! "Protocol family not supported");
}
! if (family == StandardProtocolFamily.INET6) {
if (!Net.isIPv6Available()) {
throw new UnsupportedOperationException(
"IPv6 not available");
}
}
this.family = family;
}
- private RdmaSocketImpl(Void unused) { }
-
private static volatile boolean checkedRdma;
private static volatile boolean isRdmaAvailable;
boolean isRdmaAvailable() {
if (!checkedRdma) {
--- 115,141 ----
return null;
}
}
public RdmaSocketImpl(ProtocolFamily family) {
! this(checkSupported(), family);
! }
!
! private RdmaSocketImpl(Void unused, ProtocolFamily family) {
! Objects.requireNonNull(family, "null family");
! if (!(family == INET || family == INET6)) {
! throw new UnsupportedOperationException("Protocol family not supported");
}
! if (family == INET6) {
if (!Net.isIPv6Available()) {
throw new UnsupportedOperationException(
"IPv6 not available");
}
}
this.family = family;
}
private static volatile boolean checkedRdma;
private static volatile boolean isRdmaAvailable;
boolean isRdmaAvailable() {
if (!checkedRdma) {
*** 173,184 ****
protected synchronized void create(boolean stream) throws IOException {
this.stream = stream;
if (stream) {
fd = new FileDescriptor();
! boolean preferIPv6 = Net.isIPv6Available() &&
! (family != StandardProtocolFamily.INET);
rdmaSocketCreate(preferIPv6, true);
}
}
protected void connect(String host, int port)
--- 167,177 ----
protected synchronized void create(boolean stream) throws IOException {
this.stream = stream;
if (stream) {
fd = new FileDescriptor();
! boolean preferIPv6 = Net.isIPv6Available() && (family != INET);
rdmaSocketCreate(preferIPv6, true);
}
}
protected void connect(String host, int port)
*** 200,217 ****
}
}
}
protected void connect(InetAddress address, int port) throws IOException {
! if (family == StandardProtocolFamily.INET
! && !(address instanceof Inet4Address))
! throw new IllegalArgumentException(
! "address type not match");
! if (family == StandardProtocolFamily.INET6
! && !(address instanceof Inet6Address))
! throw new IllegalArgumentException(
! "address type not match");
this.port = port;
this.address = address;
try {
connectToAddress(address, port, timeout);
--- 193,206 ----
}
}
}
protected void connect(InetAddress address, int port) throws IOException {
! if (family == INET && !(address instanceof Inet4Address))
! throw new IllegalArgumentException("address type mismatch");
! if (family == INET6 && !(address instanceof Inet6Address))
! throw new IllegalArgumentException("address type mismatch");
this.port = port;
this.address = address;
try {
connectToAddress(address, port, timeout);
*** 228,245 ****
try {
if (address == null || !(address instanceof InetSocketAddress))
throw new IllegalArgumentException("unsupported address type");
InetSocketAddress addr = (InetSocketAddress) address;
InetAddress ia = addr.getAddress();
! if (family == StandardProtocolFamily.INET
! && !(ia instanceof Inet4Address))
! throw new IllegalArgumentException(
! "address type not match");
! if (family == StandardProtocolFamily.INET6
! && !(ia instanceof Inet6Address))
! throw new IllegalArgumentException(
! "address type not match");
if (addr.isUnresolved())
throw new UnknownHostException(addr.getHostName());
this.port = addr.getPort();
this.address = addr.getAddress();
--- 217,230 ----
try {
if (address == null || !(address instanceof InetSocketAddress))
throw new IllegalArgumentException("unsupported address type");
InetSocketAddress addr = (InetSocketAddress) address;
InetAddress ia = addr.getAddress();
! if (family == INET && !(ia instanceof Inet4Address))
! throw new IllegalArgumentException("address type mismatch");
! if (family == INET6 && !(ia instanceof Inet6Address))
! throw new IllegalArgumentException("address type mismatch");
if (addr.isUnresolved())
throw new UnknownHostException(addr.getHostName());
this.port = addr.getPort();
this.address = addr.getAddress();
*** 370,381 ****
synchronized void doConnect(InetAddress address, int port, int timeout)
throws IOException {
try {
acquireFD();
! boolean preferIPv6 = Net.isIPv6Available() &&
! (family != StandardProtocolFamily.INET);
try {
rdmaSocketConnect(preferIPv6, address, port, timeout);
synchronized (fdLock) {
if (closePending) {
throw new SocketException ("Socket closed");
--- 355,365 ----
synchronized void doConnect(InetAddress address, int port, int timeout)
throws IOException {
try {
acquireFD();
! boolean preferIPv6 = Net.isIPv6Available() && (family != INET);
try {
rdmaSocketConnect(preferIPv6, address, port, timeout);
synchronized (fdLock) {
if (closePending) {
throw new SocketException ("Socket closed");
*** 388,411 ****
close();
throw e;
}
}
protected synchronized void bind(InetAddress address, int lport)
throws IOException {
if (address == null)
throw new IllegalArgumentException("address is null");
! if (family == StandardProtocolFamily.INET
! && !(address instanceof Inet4Address))
! throw new IllegalArgumentException(
! "address type not match");
! if (family == StandardProtocolFamily.INET6
! && !(address instanceof Inet6Address))
! throw new IllegalArgumentException(
! "address type not match");
! boolean preferIPv6 = Net.isIPv6Available() &&
! (family != StandardProtocolFamily.INET);
rdmaSocketBind(preferIPv6, address, lport);
}
protected synchronized void listen(int count) throws IOException {
rdmaSocketListen(count);
--- 372,403 ----
close();
throw e;
}
}
+ private final InetAddress anyLocalAddress() throws IOException {
+ if (family == INET)
+ return InetAddress.getByName("0.0.0.0");
+ else if (family == INET6)
+ return InetAddress.getByName("::");
+ else
+ throw new IllegalArgumentException("Unsupported address type " + family);
+ }
+
protected synchronized void bind(InetAddress address, int lport)
throws IOException {
if (address == null)
throw new IllegalArgumentException("address is null");
!
! if (address.isAnyLocalAddress())
! address = anyLocalAddress();
!
! if (family == INET && !(address instanceof Inet4Address))
! throw new IllegalArgumentException("address type mismatch");
! if (family == INET6 && !(address instanceof Inet6Address))
! throw new IllegalArgumentException("address type mismatch");
! boolean preferIPv6 = Net.isIPv6Available() && (family != INET);
rdmaSocketBind(preferIPv6, address, lport);
}
protected synchronized void listen(int count) throws IOException {
rdmaSocketListen(count);
< prev index next >