< prev index next >
src/jdk.net/linux/classes/jdk/internal/net/rdma/RdmaSocketProvider.java
Print this page
*** 27,59 ****
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.net.SocketOption;
import java.net.SocketOptions;
import java.net.StandardSocketOptions;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import jdk.net.RdmaSocketOptions;
public class RdmaSocketProvider {
- private static boolean rdmaLibInstalled = false;
- private static boolean rdmaLibChecked = false;
static class RdmaClientSocketImpl extends RdmaSocketImpl {
@Override
protected <T> void setOption(SocketOption<T> name, T value)
throws IOException {
- if(rdmaLibChecked && !rdmaLibInstalled)
- throw new UnsupportedOperationException(
- "librdmacm library is not installed!");
-
- rdmaLibChecked = true;
- try {
if (!rdmaOptions.isOptionSupported(name)) {
int opt;
if (name == StandardSocketOptions.SO_SNDBUF) {
opt = SocketOptions.SO_SNDBUF;
} else if (name == StandardSocketOptions.SO_RCVBUF) {
--- 27,66 ----
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
+ import java.net.SocketImpl;
import java.net.SocketOption;
import java.net.SocketOptions;
import java.net.StandardSocketOptions;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import jdk.net.RdmaSocketOptions;
public class RdmaSocketProvider {
static class RdmaClientSocketImpl extends RdmaSocketImpl {
+ private final Set<SocketOption<?>> options =
+ Set.of(StandardSocketOptions.SO_SNDBUF,
+ StandardSocketOptions.SO_RCVBUF,
+ StandardSocketOptions.SO_REUSEADDR,
+ StandardSocketOptions.TCP_NODELAY,
+ RdmaSocketOptions.RDMA_SQSIZE,
+ RdmaSocketOptions.RDMA_RQSIZE,
+ RdmaSocketOptions.RDMA_INLINE);
+
+ @Override
+ public Set<SocketOption<?>> supportedOptions() {
+ return options;
+ }
+
@Override
protected <T> void setOption(SocketOption<T> name, T value)
throws IOException {
if (!rdmaOptions.isOptionSupported(name)) {
int opt;
if (name == StandardSocketOptions.SO_SNDBUF) {
opt = SocketOptions.SO_SNDBUF;
} else if (name == StandardSocketOptions.SO_RCVBUF) {
*** 68,95 ****
}
setOption(opt, value);
} else {
rdmaOptions.setOption(fd, name, value);
}
- rdmaLibInstalled = true;
- } catch (ExceptionInInitializerError e) {
- rdmaLibInstalled = false;
- throw new UnsupportedOperationException(
- "librdmacm library is not installed!");
- }
}
@SuppressWarnings("unchecked")
@Override
protected <T> T getOption(SocketOption<T> name) throws IOException {
- if(rdmaLibChecked && !rdmaLibInstalled)
- throw new UnsupportedOperationException(
- "librdmacm library is not installed!");
-
- rdmaLibChecked = true;
Object value;
- try {
if (!rdmaOptions.isOptionSupported(name)) {
int opt;
if (name == StandardSocketOptions.SO_SNDBUF) {
opt = SocketOptions.SO_SNDBUF;
} else if (name == StandardSocketOptions.SO_RCVBUF) {
--- 75,90 ----
*** 104,135 ****
}
value = getOption(opt);
} else {
value = rdmaOptions.getOption(fd, name);
}
- rdmaLibInstalled = true;
return (T) value;
- } catch (ExceptionInInitializerError e) {
- rdmaLibInstalled = false;
- throw new UnsupportedOperationException(
- "librdmacm library is not installed!");
- }
}
}
static class RdmaServerSocketImpl extends RdmaSocketImpl {
@Override
protected <T> void setOption(SocketOption<T> name, T value)
throws IOException {
- if(rdmaLibChecked && !rdmaLibInstalled)
- throw new UnsupportedOperationException(
- "librdmacm library is not installed!");
-
- rdmaLibChecked = true;
-
- try {
if (!rdmaOptions.isOptionSupported(name)) {
int opt;
if (name == StandardSocketOptions.SO_RCVBUF) {
opt = SocketOptions.SO_RCVBUF;
} else if (name == StandardSocketOptions.SO_REUSEADDR) {
--- 99,128 ----
}
value = getOption(opt);
} else {
value = rdmaOptions.getOption(fd, name);
}
return (T) value;
}
}
static class RdmaServerSocketImpl extends RdmaSocketImpl {
+ private final Set<SocketOption<?>> options =
+ Set.of(StandardSocketOptions.SO_RCVBUF,
+ StandardSocketOptions.SO_REUSEADDR,
+ RdmaSocketOptions.RDMA_SQSIZE,
+ RdmaSocketOptions.RDMA_RQSIZE,
+ RdmaSocketOptions.RDMA_INLINE);
+
+ @Override
+ public Set<SocketOption<?>> supportedOptions() {
+ return options;
+ }
@Override
protected <T> void setOption(SocketOption<T> name, T value)
throws IOException {
if (!rdmaOptions.isOptionSupported(name)) {
int opt;
if (name == StandardSocketOptions.SO_RCVBUF) {
opt = SocketOptions.SO_RCVBUF;
} else if (name == StandardSocketOptions.SO_REUSEADDR) {
*** 140,255 ****
}
setOption(opt, value);
} else {
rdmaOptions.setOption(fd, name, value);
}
- rdmaLibInstalled = true;
- } catch (ExceptionInInitializerError e) {
- rdmaLibInstalled = false;
- throw new UnsupportedOperationException(
- "librdmacm library is not installed!");
- }
}
@SuppressWarnings("unchecked")
@Override
protected <T> T getOption(SocketOption<T> name) throws IOException {
- if(rdmaLibChecked && !rdmaLibInstalled)
- throw new UnsupportedOperationException(
- "librdmacm library is not installed!");
-
- rdmaLibChecked = true;
Object value;
- try {
if (!rdmaOptions.isOptionSupported(name)) {
int opt;
if (name == StandardSocketOptions.SO_RCVBUF) {
opt = SocketOptions.SO_RCVBUF;
} else if (name == StandardSocketOptions.SO_REUSEADDR) {
opt = SocketOptions.SO_REUSEADDR;
} else {
throw new UnsupportedOperationException(
"unsupported option: " + name);
}
- rdmaLibInstalled = true;
value = getOption(opt);
} else {
- rdmaLibInstalled = true;
value = rdmaOptions.getOption(fd, name);
}
- rdmaLibInstalled = true;
return (T) value;
- } catch (ExceptionInInitializerError e) {
- rdmaLibInstalled = false;
- throw new UnsupportedOperationException(
- "librdmacm library is not installed!");
- }
}
}
public static Socket openSocket() throws IOException {
! if(rdmaLibChecked && !rdmaLibInstalled)
! throw new UnsupportedOperationException(
! "librdmacm library is not installed!");
!
! rdmaLibChecked = true;
!
! RdmaClientSocketImpl impl;
! try {
! impl = new RdmaClientSocketImpl();
! rdmaLibInstalled = true;
! } catch (ExceptionInInitializerError e) {
! rdmaLibInstalled = false;
! throw new UnsupportedOperationException(
! "librdmacm library is not installed!");
! }
! Socket s = new Socket(impl) {
! private final Set<SocketOption<?>> options =
! Set.of(StandardSocketOptions.SO_SNDBUF,
! StandardSocketOptions.SO_RCVBUF,
! StandardSocketOptions.SO_REUSEADDR,
! StandardSocketOptions.TCP_NODELAY,
! RdmaSocketOptions.RDMA_SQSIZE,
! RdmaSocketOptions.RDMA_RQSIZE,
! RdmaSocketOptions.RDMA_INLINE);
!
! @Override
! public Set<SocketOption<?>> supportedOptions() {
! return options;
! }
! };
! return s;
}
public static ServerSocket openServerSocket() throws IOException {
! if(rdmaLibChecked && !rdmaLibInstalled)
! throw new UnsupportedOperationException(
! "librdmacm library is not installed!");
!
! rdmaLibChecked = true;
!
! RdmaServerSocketImpl impl;
! try {
! impl = new RdmaServerSocketImpl();
! rdmaLibInstalled = true;
! } catch (ExceptionInInitializerError e) {
! rdmaLibInstalled = false;
! throw new UnsupportedOperationException(
! "librdmacm library is not installed!");
! }
! ServerSocket ss = new ServerSocket(impl) {
! private final Set<SocketOption<?>> options =
! Set.of(StandardSocketOptions.SO_RCVBUF,
! StandardSocketOptions.SO_REUSEADDR,
! RdmaSocketOptions.RDMA_SQSIZE,
! RdmaSocketOptions.RDMA_RQSIZE,
! RdmaSocketOptions.RDMA_INLINE);
!
! @Override
! public Set<SocketOption<?>> supportedOptions() {
! return options;
! }
public Socket accept() throws IOException {
if (isClosed())
throw new SocketException("Socket is closed");
if (!isBound())
throw new SocketException("Socket is not bound yet");
--- 133,172 ----
}
setOption(opt, value);
} else {
rdmaOptions.setOption(fd, name, value);
}
}
@SuppressWarnings("unchecked")
@Override
protected <T> T getOption(SocketOption<T> name) throws IOException {
Object value;
if (!rdmaOptions.isOptionSupported(name)) {
int opt;
if (name == StandardSocketOptions.SO_RCVBUF) {
opt = SocketOptions.SO_RCVBUF;
} else if (name == StandardSocketOptions.SO_REUSEADDR) {
opt = SocketOptions.SO_REUSEADDR;
} else {
throw new UnsupportedOperationException(
"unsupported option: " + name);
}
value = getOption(opt);
} else {
value = rdmaOptions.getOption(fd, name);
}
return (T) value;
}
}
public static Socket openSocket() throws IOException {
! return new Socket(new RdmaClientSocketImpl()) { };
}
public static ServerSocket openServerSocket() throws IOException {
! return new ServerSocket( new RdmaServerSocketImpl()) {
public Socket accept() throws IOException {
if (isClosed())
throw new SocketException("Socket is closed");
if (!isBound())
throw new SocketException("Socket is not bound yet");
*** 257,266 ****
Socket s = openSocket();
implAccept(s);
return s;
}
};
- return ss;
}
private RdmaSocketProvider() {}
}
--- 174,182 ----
< prev index next >