From d71839cc72b0478463b021f4a700b1d3cdd94fb1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christian=20Kohlschu=CC=88tter?=
_vsockPort
appended to it (with {@code vsockPort} being replaced
+ * by the corresponding port number).
+ * @param allowedCID The permitted CID, or {@link AFVSOCKSocketAddress#VMADDR_CID_ANY} for "any".
+ * @return The instance.
+ */
+ public static AFServerSocketConnectorbind
.
- *
+ *
* @param instanceSupplier The constructor of the concrete subclass.
* @param forceAddr The address to use.
* @param The concrete {@link AFSocketAddress} that is supported by this type.
@@ -216,7 +216,7 @@ protected static AFServerSocket forceBindOn(
* Forces the address to be used for any subsequent call to {@link #bind(SocketAddress)} to be the
* given one, regardless of what'll be passed to {@link #bind(SocketAddress, int)}, but doesn't
* bind yet.
- *
+ *
* @param endpoint The forced endpoint address.
* @return This {@link AFServerSocket}.
*/
@@ -323,7 +323,7 @@ AFSocket accept1(boolean throwOnFail) throws IOException {
/**
* Returns a new {@link AFSocket} instance.
- *
+ *
* @return The new instance.
* @throws IOException on error.
*/
@@ -381,7 +381,7 @@ && isDeleteOnClose()) {
/**
* Registers a {@link Closeable} that should be closed when this socket is closed.
- *
+ *
* @param closeable The closeable.
*/
public final void addCloseable(Closeable closeable) {
@@ -390,7 +390,7 @@ public final void addCloseable(Closeable closeable) {
/**
* Unregisters a previously registered {@link Closeable}.
- *
+ *
* @param closeable The closeable.
*/
public final void removeCloseable(Closeable closeable) {
@@ -399,7 +399,7 @@ public final void removeCloseable(Closeable closeable) {
/**
* Checks whether everything is setup to support junixsocket sockets.
- *
+ *
* @return {@code true} if supported.
*/
public static boolean isSupported() {
@@ -417,10 +417,10 @@ public static boolean isSupported() {
/**
* Checks if the local socket address returned by {@link #getLocalSocketAddress()} is still valid.
- *
+ *
* The address is no longer valid if the server socket has been closed, {@code null}, or another
* server socket has been bound on that address.
- *
+ *
* @return {@code true} iff still valid.
*/
public boolean isLocalSocketAddressValid() {
@@ -460,10 +460,10 @@ public final int getLocalPort() {
/**
* Checks if this {@link AFServerSocket}'s file should be removed upon {@link #close()}.
- *
+ *
* Deletion is not guaranteed, especially when not supported (e.g., addresses in the abstract
* namespace).
- *
+ *
* @return {@code true} if an attempt is made to delete the socket file upon {@link #close()}.
*/
public final boolean isDeleteOnClose() {
@@ -473,10 +473,10 @@ public final boolean isDeleteOnClose() {
/**
* Enables/disables deleting this {@link AFServerSocket}'s file (or other resource type) upon
* {@link #close()}.
- *
+ *
* Deletion is not guaranteed, especially when not supported (e.g., addresses in the abstract
* namespace).
- *
+ *
* @param b Enabled if {@code true}.
*/
public final void setDeleteOnClose(boolean b) {
@@ -507,7 +507,7 @@ public final FileDescriptor getFileDescriptor() throws IOException {
/**
* Returns the address family supported by this implementation.
- *
+ *
* @return The family.
*/
protected final AFAddressFamily addressFamily() {
@@ -517,9 +517,9 @@ protected final AFAddressFamily addressFamily() {
/**
* Sets the hook for any subsequent call to {@link #bind(SocketAddress)} and
* {@link #bind(SocketAddress, int)} to be the given function.
- *
+ *
* The function can monitor calls or even alter the endpoint address.
- *
+ *
* @param hook The function that gets called for each {@code bind} call.
* @return This instance.
*/
diff --git a/junixsocket-common/src/main/java/org/newsclub/net/unix/AFServerSocketChannel.java b/junixsocket-common/src/main/java/org/newsclub/net/unix/AFServerSocketChannel.java
index 87dd4c5a9..cd774e15b 100644
--- a/junixsocket-common/src/main/java/org/newsclub/net/unix/AFServerSocketChannel.java
+++ b/junixsocket-common/src/main/java/org/newsclub/net/unix/AFServerSocketChannel.java
@@ -33,7 +33,7 @@
/**
* A selectable channel for stream-oriented listening sockets.
- *
+ *
* @param The concrete {@link AFSocketAddress} that is supported by this type.
* @author Christian Kohlschütter
*/
@@ -43,7 +43,7 @@ public abstract class AFServerSocketChannel extends S
/**
* Creates a new {@link AFServerSocketChannel} instance.
- *
+ *
* @param socket The corresponding {@link ServerSocket}.
* @param sp The corresponding {@link SelectorProvider}.
*/
@@ -116,10 +116,10 @@ public final AFSocketAddress getLocalAddress() throws IOException {
/**
* Checks if the local socket address returned by {@link #getLocalAddress()} is still valid.
- *
+ *
* The address is no longer valid if the server socket has been closed, {@code null}, or another
* server socket has been bound on that address.
- *
+ *
* @return {@code true} iff still valid.
*/
public final boolean isLocalSocketAddressValid() {
@@ -147,10 +147,10 @@ public final FileDescriptor getFileDescriptor() throws IOException {
/**
* Checks if this {@link AFServerSocketChannel}'s file should be removed upon {@link #close()}.
- *
+ *
* Deletion is not guaranteed, especially when not supported (e.g., addresses in the abstract
* namespace).
- *
+ *
* @return {@code true} if an attempt is made to delete the socket file upon {@link #close()}.
*/
public final boolean isDeleteOnClose() {
@@ -160,10 +160,10 @@ public final boolean isDeleteOnClose() {
/**
* Enables/disables deleting this {@link AFServerSocketChannel}'s file (or other resource type)
* upon {@link #close()}.
- *
+ *
* Deletion is not guaranteed, especially when not supported (e.g., addresses in the abstract
* namespace).
- *
+ *
* @param b Enabled if {@code true}.
*/
public final void setDeleteOnClose(boolean b) {
diff --git a/junixsocket-common/src/main/java/org/newsclub/net/unix/AFServerSocketConnector.java b/junixsocket-common/src/main/java/org/newsclub/net/unix/AFServerSocketConnector.java
index 9946b31f1..a8558dd06 100644
--- a/junixsocket-common/src/main/java/org/newsclub/net/unix/AFServerSocketConnector.java
+++ b/junixsocket-common/src/main/java/org/newsclub/net/unix/AFServerSocketConnector.java
@@ -32,7 +32,7 @@
public interface AFServerSocketConnector {
/**
* Creates an {@link AFServerSocket} bound to the given address.
- *
+ *
* @param addr The address to bind to.
* @return The bound socket.
* @throws IOException on error.
diff --git a/junixsocket-common/src/main/java/org/newsclub/net/unix/AFSocket.java b/junixsocket-common/src/main/java/org/newsclub/net/unix/AFSocket.java
index 6df312e17..4e06ec5b3 100644
--- a/junixsocket-common/src/main/java/org/newsclub/net/unix/AFSocket.java
+++ b/junixsocket-common/src/main/java/org/newsclub/net/unix/AFSocket.java
@@ -33,7 +33,7 @@
/**
* junixsocket's base implementation of a {@link Socket}.
- *
+ *
* @param The concrete {@link AFSocketAddress} that is supported by this type.
* @author Christian Kohlschütter
*/
@@ -60,7 +60,7 @@ public abstract class AFSocket extends Socket impleme
/**
* Creates a new {@link AFSocket} instance.
- *
+ *
* @param impl The corresponding {@link SocketImpl} class.
* @param afh The conversion helper to get a socket address from an encoded hostname.
* @throws SocketException on error.
@@ -74,7 +74,7 @@ protected AFSocket(final AFSocketImpl impl, AFSocketAddressFromHostname af
/**
* Returns the {@link AFSocketAddress} type supported by this socket.
- *
+ *
* @return The supported {@link AFSocketAddress}.
*/
protected final Class extends AFSocketAddress> socketAddressClass() {
@@ -83,21 +83,21 @@ protected final Class extends AFSocketAddress> socketAddressClass() {
/**
* Creates a new {@link AFSocketChannel} for this socket.
- *
+ *
* @return The new instance.
*/
protected abstract AFSocketChannel newChannel();
/**
* The reference to the constructor of an {@link AFSocket} subclass.
- *
+ *
* @param The concrete {@link AFSocketAddress} that is supported by this type.
*/
@FunctionalInterface
public interface Constructor {
/**
* Constructs a new {@link AFSocket} subclass instance.
- *
+ *
* @param fdObj The file descriptor.
* @param factory The socket factory instance.
* @return The instance.
@@ -141,12 +141,12 @@ static AFSocket newInstance(Constructor constr
/**
* Creates a new, unbound {@link AFSocket}.
- *
+ *
* This "default" implementation is a bit "lenient" with respect to the specification.
- *
+ *
* In particular, we may ignore calls to {@link Socket#getTcpNoDelay()} and
* {@link Socket#setTcpNoDelay(boolean)}.
- *
+ *
* @param The corresponding address type.
* @param constr The implementation's {@link AFSocket} constructor
* @param factory The corresponding socket factory, or {@code null}.
@@ -166,7 +166,7 @@ protected static final AFSocket newInstance(Const
/**
* Creates a new {@link AFSocket} and connects it to the given {@link AFSocketAddress}.
- *
+ *
* @param The corresponding address type.
* @param constr The implementation's {@link AFSocket} constructor
* @param addr The address to connect to.
@@ -183,7 +183,7 @@ protected static final AFSocket newInstance(Const
/**
* Creates a new {@link AFSocket} and connects it to the given {@link AFSocketAddress} using the
* default implementation suited for that address type.
- *
+ *
* @param The corresponding address type.
* @param addr The address to connect to.
* @return A new, connected socket.
@@ -198,7 +198,7 @@ public static final AFSocket> connectTo(@NonNull A
/**
* Not supported, since it's not necessary for client sockets.
- *
+ *
* @see AFServerSocket
*/
@Override
@@ -302,10 +302,10 @@ final String toStringSuffix() {
/**
* Returns true
iff {@link AFSocket}s are supported by the current Java VM.
- *
+ *
* To support {@link AFSocket}s, a custom JNI library must be loaded that is supplied with
* junixsocket.
- *
+ *
* @return {@code true} iff supported.
*/
public static boolean isSupported() {
@@ -314,9 +314,9 @@ public static boolean isSupported() {
/**
* Checks if {@link AFSocket}s are supported by the current Java VM.
- *
+ *
* If not, an {@link UnsupportedOperationException} is thrown.
- *
+ *
* @throws UnsupportedOperationException if not supported.
*/
public static void ensureSupported() throws UnsupportedOperationException {
@@ -325,9 +325,9 @@ public static void ensureSupported() throws UnsupportedOperationException {
/**
* Returns the version of the junixsocket library, as a string, for debugging purposes.
- *
+ *
* NOTE: Do not rely on the format of the version identifier, use socket capabilities instead.
- *
+ *
* @return String The version identifier, or {@code null} if it could not be determined.
* @see #supports(AFSocketCapability)
*/
@@ -342,9 +342,9 @@ public static final String getVersion() {
/**
* Returns an identifier of the loaded native library, or {@code null} if the library hasn't been
* loaded yet.
- *
+ *
* The identifier is useful mainly for debugging purposes.
- *
+ *
* @return The identifier of the loaded junixsocket-native library, or {@code null}.
*/
public static final String getLoadedLibrary() {
@@ -400,12 +400,12 @@ private static boolean isCapDisabled(AFSocketCapability cap) {
/**
* Checks if the current environment (system platform, native library, etc.) supports a given
* junixsocket capability.
- *
+ *
* Deprecated. Please use {@link #supports(AFSocketCapability)} instead.
- *
+ *
* NOTE: The result may or may not be cached from a previous call or from a check upon
* initialization.
- *
+ *
* @param capability The capability.
* @return true if supported.
* @see #supports(AFSocketCapability)
@@ -418,10 +418,10 @@ public static final boolean supports(AFUNIXSocketCapability capability) {
/**
* Checks if the current environment (system platform, native library, etc.) supports a given
* junixsocket capability.
- *
+ *
* NOTE: The result may or may not be cached from a previous call or from a check upon
* initialization.
- *
+ *
* @param capability The capability.
* @return true if supported.
*/
@@ -442,7 +442,7 @@ public final synchronized void close() throws IOException {
/**
* Registers a {@link Closeable} that should be closed when this socket is closed.
- *
+ *
* @param closeable The closeable.
*/
public final void addCloseable(Closeable closeable) {
@@ -451,7 +451,7 @@ public final void addCloseable(Closeable closeable) {
/**
* Unregisters a previously registered {@link Closeable}.
- *
+ *
* @param closeable The closeable.
*/
public final void removeCloseable(Closeable closeable) {
@@ -514,7 +514,7 @@ public final AFOutputStream getOutputStream() throws IOException {
/**
* Returns the internal helper instance for address-specific extensions.
- *
+ *
* @return The helper instance.
* @throws UnsupportedOperationException if such extensions are not supported for this address
* type.
@@ -526,7 +526,7 @@ protected final AFSocketImplExtensions getImplExtensions() {
/**
* Forces the address to be used for any subsequent call to {@link #connect(SocketAddress)} to be
* the given one, regardless of what'll be passed there.
- *
+ *
* @param endpoint The forced endpoint address.
* @return This instance.
*/
@@ -539,9 +539,9 @@ public final AFSocket forceConnectAddress(SocketAddress endpoint) {
/**
* Sets the hook for any subsequent call to {@link #connect(SocketAddress)} or
* {@link #connect(SocketAddress, int)} to be the given function.
- *
+ *
* The function can monitor events or even alter the target address.
- *
+ *
* @param hook The function that gets called for each connect call.
* @return This instance.
*/
@@ -552,10 +552,10 @@ public final AFSocket connectHook(SocketAddressFilter hook) {
/**
* Probes the status of the socket connection.
- *
+ *
* This usually involves checking for {@link #isConnected()}, and if assumed connected, also
* sending a zero-length message to the remote.
- *
+ *
* @return {@code true} if the connection is known to be closed, {@code false} if the connection
* is open/not closed or the condition is unknown.
* @throws IOException on an unexpected error.
diff --git a/junixsocket-common/src/main/java/org/newsclub/net/unix/AFSocketAddress.java b/junixsocket-common/src/main/java/org/newsclub/net/unix/AFSocketAddress.java
index 13ff3a541..f95bc2ada 100644
--- a/junixsocket-common/src/main/java/org/newsclub/net/unix/AFSocketAddress.java
+++ b/junixsocket-common/src/main/java/org/newsclub/net/unix/AFSocketAddress.java
@@ -39,7 +39,7 @@
/**
* Some {@link SocketAddress} that is supported by junixsocket, such as {@link AFUNIXSocketAddress}.
- *
+ *
* @author Christian Kohlschütter
*/
public abstract class AFSocketAddress extends InetSocketAddress {
@@ -96,7 +96,7 @@ protected ByteBuffer initialValue() {
/**
* Creates a new socket address.
- *
+ *
* @param port The port.
* @param socketAddress The socket address in junixsocket-specific byte-array representation.
* @param nativeAddress The socket address in system-native representation.
@@ -108,7 +108,7 @@ protected AFSocketAddress(int port, final byte[] socketAddress, ByteBuffer nativ
/*
* Initializing the superclass with an unresolved hostname helps us pass the #equals and
* #hashCode checks, which unfortunately are declared final in InetSocketAddress.
- *
+ *
* Using a resolved address (with the address bit initialized) would be ideal, but resolved
* addresses can only be IPv4 or IPv6 (at least as of Java 16 and earlier).
*/
@@ -136,7 +136,7 @@ protected AFSocketAddress(int port, final byte[] socketAddress, ByteBuffer nativ
/**
* Only for {@link SentinelSocketAddress}.
- *
+ *
* @param clazz The {@link SentinelSocketAddress} class.
* @param port A sentinel port number.
*/
@@ -150,17 +150,17 @@ protected AFSocketAddress(Class
*
bind
.
- *
+ *
* @param forceAddr The address to use.
* @return The new, yet unbound {@link AFServerSocket}.
* @throws IOException if an exception occurs.
@@ -148,7 +148,7 @@ protected AFUNIXSocketImpl newImpl(FileDescriptor fdObj) throws SocketException
/**
* Returns a new {@link AFSocket} instance.
- *
+ *
* @return The new instance.
* @throws IOException on error.
*/
diff --git a/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXServerSocketChannel.java b/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXServerSocketChannel.java
index be58f5b93..527515213 100644
--- a/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXServerSocketChannel.java
+++ b/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXServerSocketChannel.java
@@ -21,7 +21,7 @@
/**
* A selectable channel for stream-oriented listening sockets.
- *
+ *
* @author Christian Kohlschütter
*/
public final class AFUNIXServerSocketChannel extends AFServerSocketChanneltrue
iff {@link AFUNIXSocket}s are supported by the current Java VM.
- *
+ *
* To support {@link AFSocket}s, a custom JNI library must be loaded that is supplied with
* junixsocket, and the system must support AF_UNIX sockets.
- *
+ *
* This call is equivalent to checking {@link AFSocket#isSupported()} and
* {@link AFSocket#supports(AFSocketCapability)} with
* {@link AFSocketCapability#CAPABILITY_UNIX_DOMAIN}.
- *
+ *
* @return {@code true} iff supported.
*/
public static boolean isSupported() {
@@ -163,9 +163,9 @@ public static boolean isSupported() {
/**
* Very basic self-test function.
- *
+ *
* Prints "supported" and "capabilities" status to System.out.
- *
+ *
* @param args ignored.
*/
public static void main(String[] args) {
diff --git a/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXSocketAddress.java b/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXSocketAddress.java
index 4325b2a56..136d06f40 100644
--- a/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXSocketAddress.java
+++ b/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXSocketAddress.java
@@ -40,10 +40,10 @@
/**
* Describes an {@link InetSocketAddress} that actually uses AF_UNIX sockets instead of AF_INET.
- *
+ *
* The ability to specify a port number is not specified by AF_UNIX sockets, but we need it
* sometimes, for example for RMI-over-AF_UNIX.
- *
+ *
* @author Christian Kohlschütter
*/
@SuppressWarnings("PMD.ShortMethodName")
@@ -86,7 +86,7 @@ private AFUNIXSocketAddress(int port, final byte[] socketAddress, ByteBuffer nat
/**
* Returns an {@link AFUNIXSocketAddress} that points to the AF_UNIX socket specified by the given
* file and port. Legacy constructor, do not use!
- *
+ *
* @param socketFile The socket to connect to.
* @throws SocketException if the operation fails.
* @deprecated Use {@link #of(File)} instead.
@@ -99,7 +99,7 @@ public AFUNIXSocketAddress(File socketFile) throws SocketException {
/**
* Returns an {@link AFUNIXSocketAddress} that points to the AF_UNIX socket specified by the given
* file. Legacy constructor, do not use!
- *
+ *
* @param socketFile The socket to connect to.
* @param port The port associated with this socket, or {@code 0} when no port should be assigned.
* @throws SocketException if the operation fails.
@@ -114,7 +114,7 @@ public AFUNIXSocketAddress(File socketFile, int port) throws SocketException {
/**
* Returns an {@link AFUNIXSocketAddress} that points to the AF_UNIX socket specified by the given
* file.
- *
+ *
* @param socketFile The socket to connect to.
* @return A corresponding {@link AFUNIXSocketAddress} instance.
* @throws SocketException if the operation fails.
@@ -126,7 +126,7 @@ public static AFUNIXSocketAddress of(final File socketFile) throws SocketExcepti
/**
* Returns an {@link AFUNIXSocketAddress} that points to the AF_UNIX socket specified by the given
* file, assigning the given port to it.
- *
+ *
* @param socketFile The socket to connect to.
* @param port The port associated with this socket, or {@code 0} when no port should be assigned.
* @return A corresponding {@link AFUNIXSocketAddress} instance.
@@ -139,10 +139,10 @@ public static AFUNIXSocketAddress of(final File socketFile, int port) throws Soc
/**
* Returns an {@link AFUNIXSocketAddress} that points to the AF_UNIX socket specified by the given
* byte sequence.
- *
+ *
* NOTE: By specifying a byte array that starts with a zero byte, you indicate that the abstract
* namespace is to be used. This feature is not available on all target platforms.
- *
+ *
* @param socketAddress The socket address (as bytes).
* @return A corresponding {@link AFUNIXSocketAddress} instance.
* @throws SocketException if the operation fails.
@@ -155,7 +155,7 @@ public static AFUNIXSocketAddress of(final byte[] socketAddress) throws SocketEx
/**
* Returns an {@link AFUNIXSocketAddress} that points to the AF_UNIX socket specified by the given
* byte sequence, assigning the given port to it.
- *
+ *
* NOTE: By specifying a byte array that starts with a zero byte, you indicate that the abstract
* namespace is to be used. This feature is not available on all target platforms.
*
@@ -173,7 +173,7 @@ public static AFUNIXSocketAddress of(final byte[] socketAddress, int port)
/**
* Returns an {@link AFUNIXSocketAddress} that points to the AF_UNIX socket specified by the given
* path.
- *
+ *
* @param socketPath The socket to connect to.
* @return A corresponding {@link AFUNIXSocketAddress} instance.
* @throws SocketException if the operation fails.
@@ -185,7 +185,7 @@ public static AFUNIXSocketAddress of(final Path socketPath) throws SocketExcepti
/**
* Returns an {@link AFUNIXSocketAddress} that points to the AF_UNIX socket specified by the given
* path, assigning the given port to it.
- *
+ *
* @param socketPath The socket to connect to.
* @param port The port associated with this socket, or {@code 0} when no port should be assigned.
* @return A corresponding {@link AFUNIXSocketAddress} instance.
@@ -197,7 +197,7 @@ public static AFUNIXSocketAddress of(final Path socketPath, int port) throws Soc
/**
* Returns an {@link AFUNIXSocketAddress} for the given URI, if possible.
- *
+ *
* @param u The URI.
* @return The address.
* @throws SocketException if the operation fails.
@@ -208,7 +208,7 @@ public static AFUNIXSocketAddress of(URI u) throws SocketException {
/**
* Returns an {@link AFUNIXSocketAddress} for the given URI, if possible.
- *
+ *
* @param u The URI.
* @param overridePort The port to forcibly use, or {@code -1} for "don't override".
* @return The address.
@@ -240,7 +240,7 @@ public static AFUNIXSocketAddress of(URI u, int overridePort) throws SocketExcep
/**
* Returns an {@link AFUNIXSocketAddress} that points to a temporary, non-existent but accessible
* path in the file system.
- *
+ *
* @return A corresponding {@link AFUNIXSocketAddress} instance.
* @throws IOException if the operation fails.
*/
@@ -251,7 +251,7 @@ public static AFUNIXSocketAddress ofNewTempFile() throws IOException {
/**
* Returns an {@link AFUNIXSocketAddress} that points to a temporary, non-existent but accessible
* path in the file system, assigning the given port to it.
- *
+ *
* @param port The port associated with this socket, or {@code 0} when no port should be assigned.
* @return A corresponding {@link AFUNIXSocketAddress} instance.
* @throws IOException if the operation fails.
@@ -274,7 +274,7 @@ static File newTempPath(boolean deleteOnExit) throws IOException {
/**
* Returns an {@link AFUNIXSocketAddress} given a special {@link InetAddress} that encodes the
* byte sequence of an AF_UNIX socket address, like those returned by {@link #wrapAddress()}.
- *
+ *
* @param address The "special" {@link InetAddress}.
* @param port The port (use 0 for "none").
* @return The {@link AFUNIXSocketAddress} instance.
@@ -287,7 +287,7 @@ public static AFUNIXSocketAddress unwrap(InetAddress address, int port) throws S
/**
* Returns an {@link AFUNIXSocketAddress} given a generic {@link SocketAddress}.
- *
+ *
* @param address The address to unwrap.
* @return The {@link AFUNIXSocketAddress} instance.
* @throws SocketException if the operation fails, for example when an unsupported address is
@@ -306,7 +306,7 @@ public static AFUNIXSocketAddress unwrap(SocketAddress address) throws SocketExc
* Returns an {@link AFUNIXSocketAddress} given a special {@link InetAddress} hostname that
* encodes the byte sequence of an AF_UNIX socket address, like those returned by
* {@link #wrapAddress()}.
- *
+ *
* @param hostname The "special" hostname, as provided by {@link InetAddress#getHostName()}.
* @param port The port (use 0 for "none").
* @return The {@link AFUNIXSocketAddress} instance.
@@ -319,11 +319,11 @@ public static AFUNIXSocketAddress unwrap(String hostname, int port) throws Socke
/**
* Convenience method to create an {@link AFUNIXSocketAddress} in the abstract namespace.
- *
+ *
* The returned socket address will use the byte representation of this identifier (using the
* system's default character encoding), prefixed with a null byte (to indicate the abstract
* namespace is used).
- *
+ *
* @param name The identifier in the abstract namespace, without trailing zero or @.
* @return The address.
* @throws SocketException if the operation fails.
@@ -334,11 +334,11 @@ public static AFUNIXSocketAddress inAbstractNamespace(String name) throws Socket
/**
* Convenience method to create an {@link AFUNIXSocketAddress} in the abstract namespace.
- *
+ *
* The returned socket address will use the byte representation of this identifier (using the
* system's default character encoding), prefixed with a null byte (to indicate the abstract
* namespace is used).
- *
+ *
* @param name The identifier in the abstract namespace, without trailing zero or @.
* @param port The port associated with this socket, or {@code 0} when no port should be assigned.
* @return The address.
@@ -380,10 +380,10 @@ public String toString() {
/**
* Returns the path to the UNIX domain socket, as a human-readable string using the default
* encoding.
- *
+ *
* For addresses in the abstract namespace, the US_ASCII encoding is used; zero-bytes are
* converted to '@', other non-printable bytes are converted to '.'
- *
+ *
* @return The path.
* @see #getPathAsBytes()
*/
@@ -411,10 +411,10 @@ public String getPath() {
/**
* Returns the {@link Charset} used to encode/decode {@link AFUNIXSocketAddress}es.
- *
+ *
* This is usually the system default charset, unless that is {@link StandardCharsets#US_ASCII}
* (7-bit), in which case {@link StandardCharsets#ISO_8859_1} is used instead.
- *
+ *
* @return The charset.
*/
public static Charset addressCharset() {
@@ -423,7 +423,7 @@ public static Charset addressCharset() {
/**
* Returns the path to the UNIX domain socket, as bytes.
- *
+ *
* @return The path.
* @see #getPath()
*/
@@ -433,7 +433,7 @@ public byte[] getPathAsBytes() {
/**
* Checks if the address is in the abstract namespace.
- *
+ *
* @return {@code true} if the address is in the abstract namespace.
*/
public boolean isInAbstractNamespace() {
@@ -462,7 +462,7 @@ public File getFile() throws FileNotFoundException {
/**
* Checks if an {@link InetAddress} can be unwrapped to an {@link AFUNIXSocketAddress}.
- *
+ *
* @param addr The instance to check.
* @return {@code true} if so.
* @see #wrapAddress()
@@ -474,7 +474,7 @@ public static boolean isSupportedAddress(InetAddress addr) {
/**
* Checks if a {@link SocketAddress} can be unwrapped to an {@link AFUNIXSocketAddress}.
- *
+ *
* @param addr The instance to check.
* @return {@code true} if so.
* @see #unwrap(InetAddress, int)
@@ -485,7 +485,7 @@ public static boolean isSupportedAddress(SocketAddress addr) {
/**
* Returns the corresponding {@link AFAddressFamily}.
- *
+ *
* @return The address family instance.
*/
@SuppressWarnings("null")
diff --git a/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXSocketCapability.java b/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXSocketCapability.java
index 8e56621a8..5caeb6ced 100644
--- a/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXSocketCapability.java
+++ b/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXSocketCapability.java
@@ -20,12 +20,12 @@
/**
* Describes junixsocket capabilities the current environment (system platform, native library,
* etc.) may or may not support.
- *
+ *
* You can check whether your environment supports a given capability by calling
* {@link AFUNIXSocket#supports(AFUNIXSocketCapability)}.
- *
+ *
* This enum is deprecated. Use {@link AFSocketCapability} instead.
- *
+ *
* @see AFSocketCapability
*/
@Deprecated
@@ -49,7 +49,7 @@ public enum AFUNIXSocketCapability {
/**
* A pair of interconnected sockets can be created natively.
- *
+ *
* This currently not possible on Windows, but instead emulated via anonymous AF_INET ports when
* you use {@link AFUNIXSocketPair}.
*/
diff --git a/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXSocketChannel.java b/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXSocketChannel.java
index a5f27583f..18d61f827 100644
--- a/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXSocketChannel.java
+++ b/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXSocketChannel.java
@@ -24,7 +24,7 @@
/**
* A selectable channel for stream-oriented connecting sockets.
- *
+ *
* @author Christian Kohlschütter
*/
public final class AFUNIXSocketChannel extends AFSocketChannel[file:%3A%2F%2F
(...)", i.e.
* encoded and without the closing bracket. Since this is an invalid hostname, it will not trigger
* a DNS lookup, but can still be used within a JDBC Connection URL.
diff --git a/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXSocketImpl.java b/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXSocketImpl.java
index 35934871b..12ae2ac1d 100644
--- a/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXSocketImpl.java
+++ b/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXSocketImpl.java
@@ -29,7 +29,7 @@ protected AFUNIXSocketImpl(FileDescriptor fdObj) throws SocketException {
/**
* Changes the behavior to be somewhat lenient with respect to the specification.
- *
+ *
* In particular, we ignore calls to {@link Socket#getTcpNoDelay()} and
* {@link Socket#setTcpNoDelay(boolean)}.
*/
diff --git a/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXSocketPair.java b/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXSocketPair.java
index 08e22cbee..68413018d 100644
--- a/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXSocketPair.java
+++ b/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXSocketPair.java
@@ -21,7 +21,7 @@
/**
* A pair of sockets.
- *
+ *
* @param * Usage: *
* FileDescriptor fd;
- *
+ *
* // succeeds if fd refers to an AF_UNIX stream socket
- * AFUNIXSocket socket = FileDescriptorCast.using(fd).as(AFUNIXSocket.class);
- *
+ * AFUNIXSocket socket = FileDescriptorCast.using(fd).as(AFUNIXSocket.class);
+ *
* // succeeds if fd refers to an AF_UNIX datagram socket
- * AFUNIXDatagramChannel channel = FileDescriptorCast.using(fd).as(AFUNIXDatagramChannel.class);
- *
+ * AFUNIXDatagramChannel channel = FileDescriptorCast.using(fd).as(AFUNIXDatagramChannel.class);
+ *
* // always succeeds
- * InputStream in = FileDescriptorCast.using(fd).as(InputStream.class);
- * OutputStream in = FileDescriptorCast.using(fd).as(OutputStream.class);
+ * InputStream in = FileDescriptorCast.using(fd).as(InputStream.class);
+ * OutputStream in = FileDescriptorCast.using(fd).as(OutputStream.class);
*
* * IMPORTANT: On some platforms (e.g., Solaris, Illumos) you may need to re-apply a read timeout @@ -66,7 +66,7 @@ * that do not encode this information directly (such as {@link AFUNIXSocketAddress} and * {@link AFTIPCSocketAddress}). *
- * + * * @author Christian Kohlschütter */ public final class FileDescriptorCast implements FileDescriptorAccess { @@ -269,7 +269,7 @@ private interface CastingProviderjava.io.tmpdir
.
- *
+ *
* @return The default instance.
* @throws IOException if the operation fails.
*/
@@ -109,7 +109,7 @@ public static AFUNIXNaming getInstance() throws IOException {
/**
* Returns a {@link AFUNIXNaming} instance which support several socket files that can be stored
* under the same, given directory.
- *
+ *
* @param socketDir The directory to store sockets in.
* @return The instance.
* @throws RemoteException if the operation fails.
@@ -121,10 +121,10 @@ public static AFUNIXNaming getInstance(final File socketDir) throws RemoteExcept
/**
* Returns a {@link AFUNIXNaming} instance which support several socket files that can be stored
* under the same, given directory.
- *
+ *
* A custom "registry port" can be specified. Typically, AF-UNIX specific ports should be above
* {@code 100000}.
- *
+ *
* @param socketDir The directory to store sockets in.
* @param registryPort The registry port. Should be above {@code 100000}.
* @return The instance.
@@ -138,10 +138,10 @@ public static AFUNIXNaming getInstance(File socketDir, final int registryPort)
/**
* Returns a {@link AFUNIXNaming} instance which support several socket files that can be stored
* under the same, given directory.
- *
+ *
* A custom "registry port" can be specified. Typically, AF-UNIX specific ports should be above
* {@code 100000}.
- *
+ *
* @param socketDir The directory to store sockets in.
* @param registryPort The registry port. Should be above {@code 100000}.
* @param socketPrefix A string to be inserted at the beginning of each socket filename, or
@@ -183,7 +183,7 @@ public AFUNIXNaming newInstance(int port) throws IOException {
/**
* Returns an {@link AFUNIXNaming} instance which only supports one file. (Probably only useful
* when you want/can access the exported {@link UnicastRemoteObject} directly)
- *
+ *
* @param socketFile The socket file.
* @return The instance.
* @throws IOException if the operation fails.
@@ -221,7 +221,7 @@ public AFUNIXRegistry createRegistry() throws RemoteException {
* Returns the socket file which is used to control the RMI registry.
*
* The file is usually in the directory returned by {@link #getRegistrySocketDir()}.
- *
+ *
* @return The directory.
*/
public File getRegistrySocketFile() {
@@ -285,7 +285,7 @@ protected void shutdownRegistryFinishingTouches() {
/**
* Returns the directory in which sockets used by this registry are located.
- *
+ *
* @return The directory.
*/
public File getRegistrySocketDir() {
diff --git a/junixsocket-rmi/src/main/java/org/newsclub/net/unix/rmi/AFUNIXRMISocketFactory.java b/junixsocket-rmi/src/main/java/org/newsclub/net/unix/rmi/AFUNIXRMISocketFactory.java
index 4f101db97..c04fb153e 100644
--- a/junixsocket-rmi/src/main/java/org/newsclub/net/unix/rmi/AFUNIXRMISocketFactory.java
+++ b/junixsocket-rmi/src/main/java/org/newsclub/net/unix/rmi/AFUNIXRMISocketFactory.java
@@ -39,7 +39,7 @@
/**
* An {@link RMISocketFactory} that supports {@link AFUNIXSocket}s.
- *
+ *
* @author Christian Kohlschütter
*/
public class AFUNIXRMISocketFactory extends AFRMISocketFactory {
@@ -56,7 +56,7 @@ public class AFUNIXRMISocketFactory extends AFRMISocketFactory {
/**
* Constructor required per definition.
- *
+ *
* @see RMISocketFactory
*/
public AFUNIXRMISocketFactory() {
@@ -65,7 +65,7 @@ public AFUNIXRMISocketFactory() {
/**
* Creates a new socket factory.
- *
+ *
* @param naming The {@link AFNaming} instance to use.
* @param socketDir The directory to store the sockets in.
* @param defaultClientFactory The default {@link RMIClientSocketFactory}.
@@ -90,7 +90,7 @@ public AFUNIXRMISocketFactory(final AFNaming naming, final File socketDir,
/**
* Creates a new socket factory.
- *
+ *
* @param naming The {@link AFNaming} instance to use.
* @param socketDir The directory to store the sockets in.
* @param defaultClientFactory The default {@link RMIClientSocketFactory}.
@@ -105,7 +105,7 @@ public AFUNIXRMISocketFactory(AFNaming naming, File socketDir,
/**
* Creates a new socket factory.
- *
+ *
* @param naming The {@link AFNaming} instance to use.
* @param socketDir The directory to store the sockets in.
* @throws IOException on error.
@@ -164,7 +164,7 @@ public boolean equals(Object other) {
/**
* The directory in which socket files are stored.
- *
+ *
* @return The directory.
*/
public File getSocketDir() {
diff --git a/junixsocket-rmi/src/main/java/org/newsclub/net/unix/rmi/AFUNIXRegistry.java b/junixsocket-rmi/src/main/java/org/newsclub/net/unix/rmi/AFUNIXRegistry.java
index 7f94a6042..f03defa1f 100644
--- a/junixsocket-rmi/src/main/java/org/newsclub/net/unix/rmi/AFUNIXRegistry.java
+++ b/junixsocket-rmi/src/main/java/org/newsclub/net/unix/rmi/AFUNIXRegistry.java
@@ -23,9 +23,9 @@
/**
* A wrapper for RMI registries, both remote and local, to allow for a clean removal of bound
* resources upon shutdown.
- *
+ *
* This subclass mostly exists for backwards compatibility.
- *
+ *
* @author Christian Kohlschütter
*/
public class AFUNIXRegistry extends AFRegistry {
diff --git a/junixsocket-rmi/src/main/java/org/newsclub/net/unix/rmi/DefaultRMIClientSocketFactory.java b/junixsocket-rmi/src/main/java/org/newsclub/net/unix/rmi/DefaultRMIClientSocketFactory.java
index a7b3cb4ca..c85243fe3 100644
--- a/junixsocket-rmi/src/main/java/org/newsclub/net/unix/rmi/DefaultRMIClientSocketFactory.java
+++ b/junixsocket-rmi/src/main/java/org/newsclub/net/unix/rmi/DefaultRMIClientSocketFactory.java
@@ -26,7 +26,7 @@
/**
* An implementation of {@link RMIClientSocketFactory}.
- *
+ *
* @see AFRMISocketFactory where we deal with {@link AFSocket}s.
*/
public final class DefaultRMIClientSocketFactory implements RMIClientSocketFactory, Serializable {
@@ -38,7 +38,7 @@ private DefaultRMIClientSocketFactory() {
/**
* Returns the singleton instance for DefaultRMIClientSocketFactory.
- *
+ *
* @return The singleton.
*/
public static DefaultRMIClientSocketFactory getInstance() {
diff --git a/junixsocket-rmi/src/main/java/org/newsclub/net/unix/rmi/DefaultRMIServerSocketFactory.java b/junixsocket-rmi/src/main/java/org/newsclub/net/unix/rmi/DefaultRMIServerSocketFactory.java
index 55c688763..dadcd675e 100644
--- a/junixsocket-rmi/src/main/java/org/newsclub/net/unix/rmi/DefaultRMIServerSocketFactory.java
+++ b/junixsocket-rmi/src/main/java/org/newsclub/net/unix/rmi/DefaultRMIServerSocketFactory.java
@@ -26,7 +26,7 @@
/**
* An implementation of {@link RMIServerSocketFactory}.
- *
+ *
* @see AFRMISocketFactory where we deal with {@link AFSocket}.
*/
public class DefaultRMIServerSocketFactory implements RMIServerSocketFactory, Serializable {
@@ -42,7 +42,7 @@ public DefaultRMIServerSocketFactory() {
/**
* Returns the singleton instance for DefaultRMIServerSocketFactory.
- *
+ *
* @return The singleton.
*/
public static DefaultRMIServerSocketFactory getInstance() {
diff --git a/junixsocket-rmi/src/main/java/org/newsclub/net/unix/rmi/RMIPorts.java b/junixsocket-rmi/src/main/java/org/newsclub/net/unix/rmi/RMIPorts.java
index 246e302c9..e1dc0aec6 100644
--- a/junixsocket-rmi/src/main/java/org/newsclub/net/unix/rmi/RMIPorts.java
+++ b/junixsocket-rmi/src/main/java/org/newsclub/net/unix/rmi/RMIPorts.java
@@ -23,7 +23,7 @@
/**
* Contains some default ports used by junixsocket for RMI-over-AF_UNIX etc.
- *
+ *
* @author Christian Kohlschütter
* @see AFRMISocketFactory
* @see AFRMIService
@@ -42,14 +42,14 @@ final class RMIPorts {
/**
* This is the port reserved for the port assigner.
- *
+ *
* @see AFRMIService
*/
static final int RMI_SERVICE_PORT = 100002;
/**
* This is the base for anonymous ports. Any anonymous port will be higher than this number.
- *
+ *
* @see AFRMIService
*/
static final int ANONYMOUS_PORT_BASE = 110000;
diff --git a/junixsocket-rmi/src/main/java/org/newsclub/net/unix/rmi/RemoteCloseable.java b/junixsocket-rmi/src/main/java/org/newsclub/net/unix/rmi/RemoteCloseable.java
index 54aa9fc48..2c09add67 100644
--- a/junixsocket-rmi/src/main/java/org/newsclub/net/unix/rmi/RemoteCloseable.java
+++ b/junixsocket-rmi/src/main/java/org/newsclub/net/unix/rmi/RemoteCloseable.java
@@ -24,17 +24,17 @@
/**
* A resource that can be exposed remotely, and closed locally as well as remotely.
- *
+ *
* @author Christian Kohlschütter
*/
public interface RemoteCloseablejava -jar junixsocket-selftest-...-jar-with-dependencies.jar
.
- *
+ *
* @author Christian Kohlschütter
*/
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.CognitiveComplexity"})
@@ -124,7 +124,7 @@ public static final SkipMode parse(String skipMode) {
/**
* maven-shade-plugin's minimizeJar isn't perfect, so we give it a little hint by adding static
* references to classes that are otherwise only found via reflection.
- *
+ *
* @author Christian Kohlschütter
*/
@SuppressFBWarnings("UUF_UNUSED_FIELD")
@@ -162,9 +162,9 @@ public void checkVM() {
/**
* Run this from the command line to ensure junixsocket works correctly on the target system.
- *
+ *
* A zero error code indicates success.
- *
+ *
* @param args Ignored.
* @throws IOException on error.
*/
@@ -324,7 +324,7 @@ public void checkCapabilities() {
/**
* Checks if any test has failed so far.
- *
+ *
* @return {@code true} if failed.
*/
public boolean isFail() {
@@ -368,7 +368,7 @@ private void checkInitError() {
/**
* Dumps the results of the selftest.
- *
+ *
*/
public void dumpResults() { // NOPMD
if (modified) {
@@ -462,7 +462,7 @@ private SkipMode getSkipModeForClass(String className) {
/**
* Runs the given test classes for the specified module.
- *
+ *
* @param module The module name.
* @param testClasses The test classes.
*/
diff --git a/junixsocket-selftest/src/main/java/org/newsclub/net/unix/selftest/SelftestProvider.java b/junixsocket-selftest/src/main/java/org/newsclub/net/unix/selftest/SelftestProvider.java
index dff5bb7c7..e4f385008 100644
--- a/junixsocket-selftest/src/main/java/org/newsclub/net/unix/selftest/SelftestProvider.java
+++ b/junixsocket-selftest/src/main/java/org/newsclub/net/unix/selftest/SelftestProvider.java
@@ -24,11 +24,11 @@
/**
* Provides references to all tests that should be included in junixsocket-selftest.
- *
+ *
* Important: This is just a dummy implementation so we can properly develop in Eclipse. The actual
* provider is in src/main/java-overlay/... and contains references to test classes from
* junixsocket-common and junixsocket-rmi, which are otherwise not accessible from this artifact.
- *
+ *
* @author Christian Kohlschütter
*/
public class SelftestProvider {
diff --git a/junixsocket-server/src/main/java/org/newsclub/net/unix/server/AFSocketServer.java b/junixsocket-server/src/main/java/org/newsclub/net/unix/server/AFSocketServer.java
index 2fa7b2964..5d704d981 100644
--- a/junixsocket-server/src/main/java/org/newsclub/net/unix/server/AFSocketServer.java
+++ b/junixsocket-server/src/main/java/org/newsclub/net/unix/server/AFSocketServer.java
@@ -27,14 +27,14 @@
/**
* A base implementation for a simple, multi-threaded socket server using {@link AFSocket}s.
- *
+ *
* @author Christian Kohlschütter
*/
public abstract class AFSocketServer extends
SocketServer, AFServerSocket extends A>> {
/**
* Creates a server using the given, bound {@link ServerSocket}.
- *
+ *
* @param serverSocket The server socket to use (must be bound).
*/
public AFSocketServer(AFServerSocket extends A> serverSocket) {
@@ -43,7 +43,7 @@ public AFSocketServer(AFServerSocket extends A> serverSocket) {
/**
* Creates a server using the given {@link SocketAddress}.
- *
+ *
* @param listenAddress The address to bind the socket on.
*/
public AFSocketServer(A listenAddress) {
diff --git a/junixsocket-server/src/main/java/org/newsclub/net/unix/server/AFUNIXSocketServer.java b/junixsocket-server/src/main/java/org/newsclub/net/unix/server/AFUNIXSocketServer.java
index 5941e9d62..edaca98fd 100644
--- a/junixsocket-server/src/main/java/org/newsclub/net/unix/server/AFUNIXSocketServer.java
+++ b/junixsocket-server/src/main/java/org/newsclub/net/unix/server/AFUNIXSocketServer.java
@@ -27,16 +27,16 @@
/**
* A base implementation for a simple, multi-threaded socket server.
- *
+ *
* This class supports both AF_UNIX and "regular" sockets.
- *
+ *
* @author Christian Kohlschütter
* @deprecated Use {@link SocketServer} or {@link AFSocketServer}
*/
public abstract class AFUNIXSocketServer extends SocketServerbind
.
- *
+ *
* @param forceAddr The address to use.
* @return The new, yet unbound {@link AFServerSocket}.
* @throws IOException if an exception occurs.
diff --git a/junixsocket-tipc/src/main/java/org/newsclub/net/unix/tipc/AFTIPCServerSocketChannel.java b/junixsocket-tipc/src/main/java/org/newsclub/net/unix/tipc/AFTIPCServerSocketChannel.java
index ddceca75e..42527b4ad 100644
--- a/junixsocket-tipc/src/main/java/org/newsclub/net/unix/tipc/AFTIPCServerSocketChannel.java
+++ b/junixsocket-tipc/src/main/java/org/newsclub/net/unix/tipc/AFTIPCServerSocketChannel.java
@@ -24,7 +24,7 @@
/**
* A selectable channel for stream-oriented listening sockets.
- *
+ *
* @author Christian Kohlschütter
*/
public final class AFTIPCServerSocketChannel extends AFServerSocketChanneltrue
iff {@link AFTIPCSocket}s (sockets of type "AF_TIPC") are supported
* by the current Java VM and the kernel.
- *
+ *
* To support {@link AFTIPCSocket}s, a custom JNI library must be loaded that is supplied with
* junixsocket, and the system must support AF_TIPC sockets.
- *
+ *
* This call is equivalent to checking {@link AFSocket#isSupported()} and
* {@link AFSocket#supports(AFSocketCapability)} with {@link AFSocketCapability#CAPABILITY_TIPC}.
- *
+ *
* @return {@code true} iff supported.
*/
public static boolean isSupported() {
@@ -76,12 +76,12 @@ protected AFTIPCSocketChannel newChannel() {
/**
* Creates a new, unbound {@link AFSocket}.
- *
+ *
* This "default" implementation is a bit "lenient" with respect to the specification.
- *
+ *
* In particular, we ignore calls to {@link Socket#getTcpNoDelay()} and
* {@link Socket#setTcpNoDelay(boolean)}.
- *
+ *
* @return A new, unbound socket.
* @throws IOException if the operation fails.
*/
@@ -95,10 +95,10 @@ static AFTIPCSocket newInstance(AFTIPCSocketFactory factory) throws SocketExcept
/**
* Creates a new, unbound, "strict" {@link AFSocket}.
- *
+ *
* This call uses an implementation that tries to be closer to the specification than
* {@link #newInstance()}, at least for some cases.
- *
+ *
* @return A new, unbound socket.
* @throws IOException if the operation fails.
*/
@@ -108,7 +108,7 @@ public static AFTIPCSocket newStrictInstance() throws IOException {
/**
* Creates a new {@link AFSocket} and connects it to the given {@link AFTIPCSocketAddress}.
- *
+ *
* @param addr The address to connect to.
* @return A new, connected socket.
* @throws IOException if the operation fails.
@@ -124,9 +124,9 @@ public AFTIPCSocketChannel getChannel() {
/**
* Very basic self-test function.
- *
+ *
* Prints "supported" and "capabilities" status to System.out.
- *
+ *
* @param args ignored.
*/
public static void main(String[] args) {
@@ -149,7 +149,7 @@ public AFTIPCDestName getDestName() {
/**
* Retrieves the 16-byte node ID given a node hash.
- *
+ *
* @param peerId The node hash.
* @return The node ID, or {@code null} if unsupported.
* @throws IOException on error.
@@ -171,7 +171,7 @@ public byte[] getNodeIdentity(AFTIPCSocketAddress address) throws IOException {
/**
* Retrieves the node ID given a node hash, as a hexadecimal string.
- *
+ *
* @param peerId The node hash.
* @return The node ID, or {@code null} if unsupported.
* @throws IOException on error.
@@ -183,7 +183,7 @@ public static String getNodeIdHexString(int peerId) throws IOException {
/**
* Retrieves the link name given a node hash and a bearer ID.
- *
+ *
* @param peerId The node hash.
* @param bearerId The bearer Id.
* @return The link name, or {@code null} if unsupported.
diff --git a/junixsocket-tipc/src/main/java/org/newsclub/net/unix/tipc/AFTIPCSocketChannel.java b/junixsocket-tipc/src/main/java/org/newsclub/net/unix/tipc/AFTIPCSocketChannel.java
index a48b807d4..70c1cea39 100644
--- a/junixsocket-tipc/src/main/java/org/newsclub/net/unix/tipc/AFTIPCSocketChannel.java
+++ b/junixsocket-tipc/src/main/java/org/newsclub/net/unix/tipc/AFTIPCSocketChannel.java
@@ -22,7 +22,7 @@
/**
* A selectable channel for stream-oriented connecting sockets.
- *
+ *
* @author Christian Kohlschütter
*/
public final class AFTIPCSocketChannel extends AFSocketChannel_vsockPort
appended to it (with {@code vsockPort} being replaced
* by the corresponding port number).
@@ -73,7 +73,7 @@ public static AFServerSocketConnectorbind
.
- *
+ *
* @param forceAddr The address to use.
* @return The new, yet unbound {@link AFServerSocket}.
* @throws IOException if an exception occurs.
diff --git a/junixsocket-vsock/src/main/java/org/newsclub/net/unix/vsock/AFVSOCKServerSocketChannel.java b/junixsocket-vsock/src/main/java/org/newsclub/net/unix/vsock/AFVSOCKServerSocketChannel.java
index 5e1ed3d0a..3add33358 100644
--- a/junixsocket-vsock/src/main/java/org/newsclub/net/unix/vsock/AFVSOCKServerSocketChannel.java
+++ b/junixsocket-vsock/src/main/java/org/newsclub/net/unix/vsock/AFVSOCKServerSocketChannel.java
@@ -24,7 +24,7 @@
/**
* A selectable channel for stream-oriented listening sockets.
- *
+ *
* @author Christian Kohlschütter
*/
public final class AFVSOCKServerSocketChannel extends AFServerSocketChanneltrue
iff {@link AFVSOCKSocket}s (sockets of type "AF_VSOCK") are supported
* by the current Java VM and the kernel.
- *
+ *
* To support {@link AFVSOCKSocket}s, a custom JNI library must be loaded that is supplied with
* junixsocket, and the system must support AF_VSOCK sockets.
- *
+ *
* This call is equivalent to checking {@link AFSocket#isSupported()} and
* {@link AFSocket#supports(AFSocketCapability)} with {@link AFSocketCapability#CAPABILITY_VSOCK}.
- *
+ *
* @return {@code true} iff supported.
*/
public static boolean isSupported() {
@@ -75,12 +75,12 @@ protected AFVSOCKSocketChannel newChannel() {
/**
* Creates a new, unbound {@link AFSocket}.
- *
+ *
* This "default" implementation is a bit "lenient" with respect to the specification.
- *
+ *
* In particular, we ignore calls to {@link Socket#getTcpNoDelay()} and
* {@link Socket#setTcpNoDelay(boolean)}.
- *
+ *
* @return A new, unbound socket.
* @throws IOException if the operation fails.
*/
@@ -94,10 +94,10 @@ static AFVSOCKSocket newInstance(AFVSOCKSocketFactory factory) throws SocketExce
/**
* Creates a new, unbound, "strict" {@link AFSocket}.
- *
+ *
* This call uses an implementation that tries to be closer to the specification than
* {@link #newInstance()}, at least for some cases.
- *
+ *
* @return A new, unbound socket.
* @throws IOException if the operation fails.
*/
@@ -107,7 +107,7 @@ public static AFVSOCKSocket newStrictInstance() throws IOException {
/**
* Creates a new {@link AFSocket} and connects it to the given {@link AFVSOCKSocketAddress}.
- *
+ *
* @param addr The address to connect to.
* @return A new, connected socket.
* @throws IOException if the operation fails.
@@ -123,7 +123,7 @@ public AFVSOCKSocketChannel getChannel() {
/**
* Returns the local CID.
- *
+ *
* If the system does not support vsock, or status about support cannot be retrieved, -1
* ({@link AFVSOCKSocketAddress#VMADDR_CID_ANY}) is returned. The value may be cached upon
* initialization of the library.
@@ -137,9 +137,9 @@ public static int getLocalCID() throws IOException {
/**
* Very basic self-test function.
- *
+ *
* Prints "supported" and "capabilities" status to System.out.
- *
+ *
* @param args ignored.
*/
public static void main(String[] args) {
diff --git a/junixsocket-vsock/src/main/java/org/newsclub/net/unix/vsock/AFVSOCKSocketChannel.java b/junixsocket-vsock/src/main/java/org/newsclub/net/unix/vsock/AFVSOCKSocketChannel.java
index 1b42310f7..d967b5f3f 100644
--- a/junixsocket-vsock/src/main/java/org/newsclub/net/unix/vsock/AFVSOCKSocketChannel.java
+++ b/junixsocket-vsock/src/main/java/org/newsclub/net/unix/vsock/AFVSOCKSocketChannel.java
@@ -22,7 +22,7 @@
/**
* A selectable channel for stream-oriented connecting sockets.
- *
+ *
* @author Christian Kohlschütter
*/
public final class AFVSOCKSocketChannel extends AFSocketChannelorg.newsclub.net.unix.library.disable.CAPABILITY_SOMETHING_SOMETHING=true
+ * when invoking the JVM (make sure this property is set before junixsocket is accessed).
*/
public enum AFSocketCapability {
// see org_newsclub_net_unix_NativeUnixSocket.c in junixsocket-native
@@ -116,6 +120,16 @@ public enum AFSocketCapability {
*/
CAPABILITY_ZERO_LENGTH_SEND(11),
+ /**
+ * Support for "unsafe" operations.
+ *
+ * Trading-in safety for speed or simplicity may be justified sometimes.
+ *
+ * @see Unsafe
+ * @see AFSocket#ensureUnsafeSupported()
+ */
+ CAPABILITY_UNSAFE(12),
+
; // end of list
private final int bitmask;
diff --git a/junixsocket-common/src/main/java/org/newsclub/net/unix/FileDescriptorCast.java b/junixsocket-common/src/main/java/org/newsclub/net/unix/FileDescriptorCast.java
index 63ef83661..e5b49b161 100644
--- a/junixsocket-common/src/main/java/org/newsclub/net/unix/FileDescriptorCast.java
+++ b/junixsocket-common/src/main/java/org/newsclub/net/unix/FileDescriptorCast.java
@@ -137,6 +137,13 @@ public FileInputStream provideAs(FileDescriptorCast fdc,
return FD_IS_PROVIDER.apply(fdc.getFileDescriptor());
}
});
+ addProvider(FileDescriptor.class, new CastingProvider+ * This method + * is inherently unsafe as it may + *
+ * Note that the values {@code 0}, {@code 1}, and {@code 2} are always mapped to + * {@link FileDescriptor#in}, {@link FileDescriptor#out}, and {@link FileDescriptor#err}, + * respectively. + * + * @param fd The system-native file descriptor value. + * @return The {@link FileDescriptorCast} instance. + * @throws IOException on error, especially if the given file descriptor is invalid or + * unsupported, or when "unsafe" operations are unavailable or manually disabled for the + * current environment. + */ + @Unsafe + public static FileDescriptorCast unsafeUsing(int fd) throws IOException { + AFSocket.ensureUnsafeSupported(); + + FileDescriptor fdObj; + + switch (fd) { + case -1: + throw new IOException("Not a valid file descriptor"); + case 0: + fdObj = FileDescriptor.in; + break; + case 1: + fdObj = FileDescriptor.out; + break; + case 2: + fdObj = FileDescriptor.err; + break; + default: + fdObj = new FileDescriptor(); + NativeUnixSocket.initFD(fdObj, fd); + break; + } + + return using(fdObj); + } + private static void triggerInit() { AFUNIXSocketAddress.addressFamily().getClass(); // trigger registration AFTIPCSocketAddress.addressFamily().getClass(); // trigger registration diff --git a/junixsocket-common/src/main/java/org/newsclub/net/unix/Unsafe.java b/junixsocket-common/src/main/java/org/newsclub/net/unix/Unsafe.java new file mode 100644 index 000000000..72e9458be --- /dev/null +++ b/junixsocket-common/src/main/java/org/newsclub/net/unix/Unsafe.java @@ -0,0 +1,41 @@ +/* + * junixsocket + * + * Copyright 2009-2022 Christian Kohlschütter + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.newsclub.net.unix; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Declares some operation "unsafe", which is guarded via + * {@link AFSocketCapability#CAPABILITY_UNSAFE}. + *
+ * Methods annotated with this type should also call {@link AFSocket#ensureUnsafeSupported()} to + * check availability at runtime. + *
+ * NOTE: This annotation has nothing to do with {@code sun.misc.Unsafe}.
+ *
+ * @author Christian Kohlschütter
+ * @see AFSocket#ensureUnsafeSupported()
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface Unsafe {
+
+}
diff --git a/junixsocket-common/src/test/java/org/newsclub/net/unix/FileDescriptorCastTest.java b/junixsocket-common/src/test/java/org/newsclub/net/unix/FileDescriptorCastTest.java
index fa812c5da..818bc2897 100644
--- a/junixsocket-common/src/test/java/org/newsclub/net/unix/FileDescriptorCastTest.java
+++ b/junixsocket-common/src/test/java/org/newsclub/net/unix/FileDescriptorCastTest.java
@@ -19,6 +19,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -104,6 +105,15 @@ public void testCastAsInteger() throws Exception {
Integer.class));
}
+ @Test
+ @AFSocketCapabilityRequirement(AFSocketCapability.CAPABILITY_UNSAFE)
+ public void testUnsafeCast() throws Exception {
+ assertEquals(1, FileDescriptorCast.unsafeUsing(1).as(Integer.class));
+ assertEquals(-2, FileDescriptorCast.unsafeUsing(-2).as(Integer.class));
+ assertSame(FileDescriptor.out, FileDescriptorCast.unsafeUsing(1).as(FileDescriptor.class));
+ assertThrows(IOException.class, () -> FileDescriptorCast.unsafeUsing(-1).as(Integer.class));
+ }
+
@Test
public void testRandomAccessFile() throws Exception {
File tempFile = AFUNIXSocketAddress.newTempPath(false);
diff --git a/junixsocket-native/src/main/c/capabilities.c b/junixsocket-native/src/main/c/capabilities.c
index a94b1347d..46375aa17 100644
--- a/junixsocket-native/src/main/c/capabilities.c
+++ b/junixsocket-native/src/main/c/capabilities.c
@@ -36,6 +36,7 @@ static int CAPABILITY_UNIX_DOMAIN = (1 << 8);
static int CAPABILITY_VSOCK = (1 << 9);
static int CAPABILITY_VSOCK_DGRAM = (1 << 10);
static int CAPABILITY_ZERO_LENGTH_SEND = (1 << 11);
+static int CAPABILITY_UNSAFE = (1 << 12);
CK_IGNORE_UNUSED_VARIABLE_END
void init_capabilities(JNIEnv *env CK_UNUSED) {
@@ -54,6 +55,10 @@ JNIEXPORT jint JNICALL Java_org_newsclub_net_unix_NativeUnixSocket_capabilities(
{
int capabilities = 0;
+#if !defined(_WIN32)
+ capabilities |= CAPABILITY_UNSAFE;
+#endif
+
if(supportsUNIX()) {
capabilities |= CAPABILITY_UNIX_DOMAIN;
diff --git a/src/site/markdown/filedescriptors.md b/src/site/markdown/filedescriptors.md
index ce7a450e6..4b0dc6b49 100644
--- a/src/site/markdown/filedescriptors.md
+++ b/src/site/markdown/filedescriptors.md
@@ -28,6 +28,12 @@ You can also get the file descriptor from some classes in the Java API, for exam
FileDescriptor stdout = FileDescriptor.out;
FileDescriptor stderr = FileDescriptor.err;
+### Getting a FileDescriptor from a native fd integer value
+
+You may use a somewhat "unsafe" operation to convert a system-native file descriptor, described as an integer value, to a `FileDescriptor` (or other types, see below), via `FileDescriptorCast.unsafeUsing(fdVal).as(FileDescriptor.class)`.
+
+This functionality may not be available in all environments (e.g., on Windows, or when manually disabled by setting the system property `-Dorg.newsclub.net.unix.library.disable.CAPABILITY_UNSAFE=true`).
+
## Sending and receiving File Descriptors
A very useful feature of Unix Domain Sockets is the ability to send and receive file descriptors
From 8bef3c8f7d1c46477d38766cb29ff8b2a588fce4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christian=20Kohlschu=CC=88tter?=
- * This method - * is inherently unsafe as it may + * This method is inherently unsafe as it may *
- * Note that the values {@code 0}, {@code 1}, and {@code 2} are always mapped to
- * {@link FileDescriptor#in}, {@link FileDescriptor#out}, and {@link FileDescriptor#err},
- * respectively.
+ * Note that attempts are made to reuse {@link FileDescriptor#in}, {@link FileDescriptor#out}, and
+ * {@link FileDescriptor#err}, respectively.
*
* @param fd The system-native file descriptor value.
* @return The {@link FileDescriptorCast} instance.
@@ -334,25 +345,28 @@ public static FileDescriptorCast unsafeUsing(int fd) throws IOException {
AFSocket.ensureUnsafeSupported();
FileDescriptor fdObj;
+ if (fd == -1) {
+ throw new IOException("Not a valid file descriptor");
+ } else if (fd == FD_IN) {
+ fdObj = FileDescriptor.in;
+ } else if (fd == FD_OUT) {
+ fdObj = FileDescriptor.out;
+ } else if (fd == FD_ERR) {
+ fdObj = FileDescriptor.err;
+ } else {
+ fdObj = null;
+ }
- switch (fd) {
- case -1:
- throw new IOException("Not a valid file descriptor");
- case 0:
- fdObj = FileDescriptor.in;
- break;
- case 1:
- fdObj = FileDescriptor.out;
- break;
- case 2:
- fdObj = FileDescriptor.err;
- break;
- default:
- fdObj = new FileDescriptor();
- NativeUnixSocket.initFD(fdObj, fd);
- break;
+ if (fdObj != null) {
+ int check = getFdIfPossible(fdObj);
+ if (fd == check) {
+ return using(fdObj);
+ }
}
+ fdObj = new FileDescriptor();
+ NativeUnixSocket.initFD(fdObj, fd);
+
return using(fdObj);
}
diff --git a/junixsocket-common/src/test/java/org/newsclub/net/unix/FileDescriptorCastTest.java b/junixsocket-common/src/test/java/org/newsclub/net/unix/FileDescriptorCastTest.java
index 818bc2897..2651a124c 100644
--- a/junixsocket-common/src/test/java/org/newsclub/net/unix/FileDescriptorCastTest.java
+++ b/junixsocket-common/src/test/java/org/newsclub/net/unix/FileDescriptorCastTest.java
@@ -19,6 +19,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
@@ -98,9 +99,10 @@ public void testStdout() throws IOException {
@Test
public void testCastAsInteger() throws Exception {
- assertEquals(0, FileDescriptorCast.using(FileDescriptor.in).as(Integer.class));
- assertEquals(1, FileDescriptorCast.using(FileDescriptor.out).as(Integer.class));
- assertEquals(2, FileDescriptorCast.using(FileDescriptor.err).as(Integer.class));
+ assertNotEquals(-1, FileDescriptorCast.using(FileDescriptor.in).as(Integer.class));
+ assertNotEquals(-1, FileDescriptorCast.using(FileDescriptor.out).as(Integer.class));
+ assertNotEquals(-1, FileDescriptorCast.using(FileDescriptor.err).as(Integer.class));
+
assertThrows(IOException.class, () -> FileDescriptorCast.using(new FileDescriptor()).as(
Integer.class));
}
@@ -110,7 +112,8 @@ public void testCastAsInteger() throws Exception {
public void testUnsafeCast() throws Exception {
assertEquals(1, FileDescriptorCast.unsafeUsing(1).as(Integer.class));
assertEquals(-2, FileDescriptorCast.unsafeUsing(-2).as(Integer.class));
- assertSame(FileDescriptor.out, FileDescriptorCast.unsafeUsing(1).as(FileDescriptor.class));
+ assertSame(FileDescriptor.out, FileDescriptorCast.unsafeUsing(FileDescriptorCast.using(
+ FileDescriptor.out).as(Integer.class)).as(FileDescriptor.class));
assertThrows(IOException.class, () -> FileDescriptorCast.unsafeUsing(-1).as(Integer.class));
}
From f8ed6d2469e531fd839897f63c4763002013a737 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christian=20Kohlschu=CC=88tter?=
*
*
@@ -82,7 +85,9 @@ public abstract class ThroughputTest extends SocketTest
protected static final int ENABLED = SystemPropertyUtil.getIntSystemProperty(
"org.newsclub.net.unix.throughput-test.enabled", 1);
protected static final int PAYLOAD_SIZE = SystemPropertyUtil.getIntSystemProperty(
- "org.newsclub.net.unix.throughput-test.payload-size", 2048); // 8192 is much faster
+ "org.newsclub.net.unix.throughput-test.payload-size", 1400); // 8192 is much faster
+ protected static final int PAYLOAD_SIZE_DATAGRAM = SystemPropertyUtil.getIntSystemProperty(
+ "org.newsclub.net.unix.throughput-test.payload-size.datagram", PAYLOAD_SIZE);
protected static final int NUM_SECONDS = SystemPropertyUtil.getIntSystemProperty(
"org.newsclub.net.unix.throughput-test.seconds", 0);
protected static final int NUM_MILLISECONDS = Math.max(50, NUM_SECONDS * 1000);
@@ -331,7 +336,8 @@ public void testDatagramPacket() throws Exception {
long sentTotal = 0;
new Thread() {
- final DatagramPacket dp = new DatagramPacket(new byte[PAYLOAD_SIZE], PAYLOAD_SIZE);
+ final DatagramPacket dp = new DatagramPacket(new byte[PAYLOAD_SIZE_DATAGRAM],
+ PAYLOAD_SIZE_DATAGRAM);
@Override
public void run() {
@@ -343,7 +349,7 @@ public void run() {
continue;
}
int read = dp.getLength();
- if (read != PAYLOAD_SIZE && read != 0) {
+ if (read != PAYLOAD_SIZE_DATAGRAM && read != 0) {
throw new IOException("Unexpected response length: " + read);
}
readTotal.addAndGet(dp.getLength());
@@ -360,7 +366,8 @@ public void run() {
long time = System.currentTimeMillis();
- DatagramPacket dp = new DatagramPacket(new byte[PAYLOAD_SIZE], PAYLOAD_SIZE);
+ DatagramPacket dp = new DatagramPacket(new byte[PAYLOAD_SIZE_DATAGRAM],
+ PAYLOAD_SIZE_DATAGRAM);
byte[] data = dp.getData();
for (int i = 0; i < data.length; i++) {
data[i] = (byte) i;
@@ -373,7 +380,7 @@ public void run() {
e.addSuppressed(new Exception(dp.getSocketAddress().toString()));
throw e;
}
- sentTotal += PAYLOAD_SIZE;
+ sentTotal += PAYLOAD_SIZE_DATAGRAM;
}
time = System.currentTimeMillis() - time;
keepRunning.set(false);
@@ -382,8 +389,8 @@ public void run() {
long readTotal0 = readTotal.get();
reportResults(stbTestType() + " DatagramPacket", ((1000f * readTotal0 / time) / 1000f
- / 1000f) + " MB/s for payload size " + PAYLOAD_SIZE + "; " + String.format(
- Locale.ENGLISH, "%.1f%% packet loss", 100 * (1 - (readTotal0
+ / 1000f) + " MB/s for datagram payload size " + PAYLOAD_SIZE_DATAGRAM + "; " + String
+ .format(Locale.ENGLISH, "%.1f%% packet loss", 100 * (1 - (readTotal0
/ (float) sentTotal))));
}
});
@@ -502,8 +509,8 @@ protected void testSocketDatagramChannel(String id, DatagramChannel ds, Datagram
new Thread() {
@Override
public void run() {
- final ByteBuffer receiveBuffer = direct ? ByteBuffer.allocateDirect(PAYLOAD_SIZE)
- : ByteBuffer.allocate(PAYLOAD_SIZE);
+ final ByteBuffer receiveBuffer = direct ? ByteBuffer.allocateDirect(PAYLOAD_SIZE_DATAGRAM)
+ : ByteBuffer.allocate(PAYLOAD_SIZE_DATAGRAM);
try {
SelectionKey key;
if (readSelector != null) {
@@ -528,7 +535,7 @@ public void run() {
}
read = ds.read(receiveBuffer);
receiveBuffer.rewind();
- if (read != PAYLOAD_SIZE && read != 0 && read != -1) {
+ if (read != PAYLOAD_SIZE_DATAGRAM && read != 0 && read != -1) {
throw new IOException("Unexpected response length: " + read);
}
readTotal.addAndGet(read);
@@ -550,8 +557,8 @@ public void run() {
time = System.currentTimeMillis();
- final ByteBuffer sendBuffer = direct ? ByteBuffer.allocateDirect(PAYLOAD_SIZE) : ByteBuffer
- .allocate(PAYLOAD_SIZE);
+ final ByteBuffer sendBuffer = direct ? ByteBuffer.allocateDirect(PAYLOAD_SIZE_DATAGRAM)
+ : ByteBuffer.allocate(PAYLOAD_SIZE_DATAGRAM);
try (AbstractSelector writeSelector = sp == null ? null : sp.openSelector()) { // NOPMD
if (sp != null) {
@@ -576,11 +583,11 @@ public void run() {
}
}
- if (written != PAYLOAD_SIZE && written != 0) {
+ if (written != PAYLOAD_SIZE_DATAGRAM && written != 0) {
throw new IOException("Unexpected written length: " + written);
}
- sentTotal += PAYLOAD_SIZE;
+ sentTotal += PAYLOAD_SIZE_DATAGRAM;
sendBuffer.rewind();
}
} finally {
@@ -599,8 +606,9 @@ public void run() {
long readTotal0 = readTotal.get();
reportResults(id + " direct=" + direct + ";blocking=" + blocking, ((1000f * readTotal0 / time)
- / 1000f / 1000f) + " MB/s for payload size " + PAYLOAD_SIZE + "; " + String.format(
- Locale.ENGLISH, "%.1f%% packet loss", 100 * (1 - (readTotal0 / (float) sentTotal))));
+ / 1000f / 1000f) + " MB/s for datagram payload size " + PAYLOAD_SIZE_DATAGRAM + "; "
+ + String.format(Locale.ENGLISH, "%.1f%% packet loss", 100 * (1 - (readTotal0
+ / (float) sentTotal))));
}
From 2ac91387b4491bb550d61856cddcd575dbc5162b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christian=20Kohlschu=CC=88tter?=
org.newsclub.net.unix.throughput-test.enabled
(0/1, default: 1)org.newsclub.net.unix.throughput-test.payload-size
(bytes, e.g., 8192)org.newsclub.net.unix.throughput-test.payload-size.datagram
(bytes, e.g., 2048;
+ * defaults to value specified with "payload-size" above)org.newsclub.net.unix.throughput-test.seconds
(default: 0)