Top Description Inners Fields Constructors Methods
org.newsclub.net.unix

public abstract Class AFSocket<A extends AFSocketAddress>

extends Socket
implements AFSomeSocket, AFSocketExtensions
Class Inheritance
All Implemented Interfaces
org.newsclub.net.unix.AFSocketExtensions, org.newsclub.net.unix.AFSomeSocket, org.newsclub.net.unix.AFSomeSocketThing, org.newsclub.net.unix.FileDescriptorAccess, java.io.Closeable, java.lang.AutoCloseable
Known Direct Subclasses
org.newsclub.net.unix.AFGenericSocket, org.newsclub.net.unix.AFUNIXSocket
Annotations
@SuppressWarnings:PMD.CouplingBetweenObjects, PMD.CyclomaticComplexity
Type Parameters
<A>
The concrete AFSocketAddress that is supported by this type.
Imports
java.io.Closeable, .FileDescriptor, .IOException, java.net.Socket, .SocketAddress, .SocketException, .SocketImpl, java.util.concurrent.atomic.AtomicBoolean, org.eclipse.jdt.annotation.NonNull, .Nullable, com.kohlschutter.annotations.compiletime.SuppressFBWarnings

junixsocket's base implementation of a Socket.
Author
Christian Kohlschütter

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
AFSocket.Constructor<
The concrete AFSocketAddress that is supported by this type.
A extends AFSocketAddress
>

The reference to the constructor of an AFSocket subclass.

Field Summary

Modifier and TypeField and Description
private final AFSocketAddressFromHostname<A>
private static Integer
private final AFSocketChannel<A>
private final Closeables
private @Nullable SocketAddressFilter
private final AtomicBoolean
private final AFSocketImpl<A>
pack-priv static String
pack-priv static final String
private static final byte[]

Constructor Summary

AccessConstructor and Description
protected
AFSocket(final AFSocketImpl<A>
The corresponding SocketImpl class.
impl
,
AFSocketAddressFromHostname<A>
The conversion helper to get a socket address from an encoded hostname.
afh
)

Creates a new AFSocket instance.

Method Summary

Modifier and TypeMethod and Description
public final void
addCloseable(Closeable
The closeable.
closeable
)

Registers a Closeable that should be closed when this socket is closed.

public final void
bind(SocketAddress
the SocketAddress to bind to
bindpoint
)

Overrides java.net.Socket.bind.

Not supported, since it's not necessary for client sockets.

private static synchronized int
public boolean

Returns:

true if the connection is known to be closed, false if the connection is open/not closed or the condition is unknown.
checkConnectionClosed
()

Probes the status of the socket connection.

public final synchronized void
close()

Overrides java.net.Socket.close.

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

public final void
connect(SocketAddress
the SocketAddress
endpoint
)

Overrides java.net.Socket.connect.

Connects this socket to the server.

public final void
connect(SocketAddress
the SocketAddress
endpoint
,
int
the timeout value to be used in milliseconds.
timeout
)

Overrides java.net.Socket.connect.

Connects this socket to the server with a specified timeout value.

pack-priv final boolean
connect0(SocketAddress endpoint, int timeout)

public final AFSocket<A>

Returns:

This instance.
connectHook
(SocketAddressFilter
The function that gets called for each connect call.
hook
)

Sets the hook for any subsequent call to connect(SocketAddress) or connect(SocketAddress, int) to be the given function.

protected static final <
The corresponding address type.
A extends AFSocketAddress
>
@NonNull AFSocket<A>

Returns:

A new, connected socket.
connectTo
(AFSocket.Constructor<A>
The implementation's AFSocket constructor
constr
,
A
The address to connect to.
addr
)

Creates a new AFSocket and connects it to the given AFSocketAddress.

public static final <
The corresponding address type.
A extends AFSocketAddress
>
AFSocket<?>

Returns:

A new, connected socket.
connectTo
(@NonNull A
The address to connect to.
addr
)

Creates a new AFSocket and connects it to the given AFSocketAddress using the default implementation suited for that address type.

public final void
ensureAncillaryReceiveBufferSize(int
The minimum size (in bytes).
minSize
)

Implements org.newsclub.net.unix.AFSocketExtensions.ensureAncillaryReceiveBufferSize.

Ensures a minimum ancillary receive buffer size.

public static void
ensureSupported()

Checks if AFSockets are supported by the current Java VM.

public static final void
ensureUnsafeSupported()

Checks if the current environment (system platform, native library, etc.) supports "unsafe" operations (as controlled via the AFSocketCapability#CAPABILITY_UNSAFE capability).

public final AFSocket<A>

Returns:

This instance.
forceConnectAddress
(SocketAddress
The forced endpoint address.
endpoint
)

Forces the address to be used for any subsequent call to connect(SocketAddress) to be the given one, regardless of what'll be passed there.

pack-priv final AFSocketImpl<A>
pack-priv final AFSocketImpl<A>
getAFImpl(boolean createSocket)

public final int
getAncillaryReceiveBufferSize()

Implements org.newsclub.net.unix.AFSocketExtensions.getAncillaryReceiveBufferSize.

Returns the size of the receive buffer for ancillary messages (in bytes).

public AFSocketChannel<A>
getChannel()

Overrides java.net.Socket.getChannel.

Returns the unique SocketChannel object associated with this socket, if any.

public final FileDescriptor
protected final AFSocketImplExtensions<A>

Returns:

The helper instance.
getImplExtensions
()

Returns the internal helper instance for address-specific extensions.

public final AFInputStream
getInputStream()

Overrides java.net.Socket.getInputStream.

Returns an input stream for this socket.

public static final String

Returns:

The identifier of the loaded junixsocket-native library, or null.
getLoadedLibrary
()

Returns an identifier of the loaded native library, or null if the library hasn't been loaded yet.

public final A
getLocalSocketAddress()

Overrides java.net.Socket.getLocalSocketAddress.

Implements org.newsclub.net.unix.AFSomeSocketThing.getLocalSocketAddress.

Returns the socket's local socket address, or null if unavailable or if there was a problem retrieving it.

public final AFOutputStream
getOutputStream()

Overrides java.net.Socket.getOutputStream.

Returns an output stream for this socket.

public final synchronized A
getRemoteSocketAddress()

Overrides java.net.Socket.getRemoteSocketAddress.

Implements org.newsclub.net.unix.AFSomeSocket.getRemoteSocketAddress.

Returns the socket's remote socket address, or null if unavailable/not connected, or if there was a problem retrieving it.

public static final String

Returns:

String The version identifier, or null if it could not be determined.
getVersion
()

Returns the version of the junixsocket library, as a string, for debugging purposes.

private static int
pack-priv final void
pack-priv final void
public final boolean
isBound()

Overrides java.net.Socket.isBound.

Returns the binding state of the socket.

private static boolean
public final boolean
isClosed()

Overrides java.net.Socket.isClosed.

Returns the closed state of the socket.

public final boolean
isConnected()

Overrides java.net.Socket.isConnected.

Returns the connection state of the socket.

public static boolean

Returns:

true if running on Android.
isRunningOnAndroid
()

Checks if we're running on Android (as far as junixsocket is concerned).

public static boolean

Returns:

true iff supported.
isSupported
()

Returns true iff AFSockets are supported by the current Java VM.

protected abstract AFSocketChannel<A>

Returns:

The new instance.
newChannel
()

Creates a new AFSocketChannel for this socket.

pack-priv static <A extends AFSocketAddress> AFSocket<A>
newInstance(AFSocket.Constructor<A> constr, AFSocketFactory<A> sf, FileDescriptor fdObj, int localPort, int remotePort)

protected static final <
The corresponding address type.
A extends AFSocketAddress
>
AFSocket<A>

Returns:

A new, unbound socket.
newInstance
(AFSocket.Constructor<A>
The implementation's AFSocket constructor
constr
,
AFSocketFactory<A>
The corresponding socket factory, or null.
factory
)

Creates a new, unbound AFSocket.

private static <A extends AFSocketAddress> @NonNull AFSocket<A>
private AFSocketAddress
public final void
removeCloseable(Closeable
The closeable.
closeable
)

Unregisters a previously registered Closeable.

public final void
setAncillaryReceiveBufferSize(int
The size.
size
)

Implements org.newsclub.net.unix.AFSocketExtensions.setAncillaryReceiveBufferSize.

Sets the size of the receive buffer for ancillary messages (in bytes).

public void
setShutdownOnClose(boolean
true if enabled.
enabled
)

Implements org.newsclub.net.unix.AFSomeSocketThing.setShutdownOnClose.

Configures whether the socket should be shutdown upon close(), which is the default.

protected final Class<? extends AFSocketAddress>

Returns:

The supported AFSocketAddress.
socketAddressClass
()

Returns the AFSocketAddress type supported by this socket.

public static final boolean

Returns:

true if supported.
supports
(AFUNIXSocketCapability
The capability.
capability
)
Deprecated

Checks if the current environment (system platform, native library, etc.) supports a given junixsocket capability.

public static final boolean

Returns:

true if supported.
supports
(AFSocketCapability
The capability.
capability
)

Checks if the current environment (system platform, native library, etc.) supports a given junixsocket capability.

public final String
toString()

Overrides java.net.Socket.toString.

Converts this socket to a String.

pack-priv final String
Inherited from java.net.Socket:
getInetAddressgetKeepAlivegetLocalAddressgetLocalPortgetOOBInlinegetOptiongetPortgetReceiveBufferSizegetReuseAddressgetSendBufferSizegetSoLingergetSoTimeoutgetTcpNoDelaygetTrafficClassisInputShutdownisOutputShutdownsendUrgentDatasetKeepAlivesetOOBInlinesetOptionsetPerformancePreferencessetReceiveBufferSizesetReuseAddresssetSendBufferSizesetSocketImplFactorysetSoLingersetSoTimeoutsetTcpNoDelaysetTrafficClassshutdownInputshutdownOutputsupportedOptions

Field Detail

afhback to summary
private final AFSocketAddressFromHostname<A> afh
capabilitiesValueback to summary
private static Integer capabilitiesValue
channelback to summary
private final AFSocketChannel<A> channel
Annotations
@SuppressWarnings:this-escape
closeablesback to summary
private final Closeables closeables
connectFilterback to summary
private @Nullable SocketAddressFilter connectFilter
createdback to summary
private final AtomicBoolean created
implback to summary
private final AFSocketImpl<A> impl

Hides java.net.Socket.impl.

loadedLibraryback to summary
pack-priv static String loadedLibrary
Annotations
@SuppressWarnings:PMD.MutableStaticState
PROP_LIBRARY_DISABLE_CAPABILITY_PREFIXback to summary
pack-priv static final String PROP_LIBRARY_DISABLE_CAPABILITY_PREFIX
ZERO_BYTESback to summary
private static final byte[] ZERO_BYTES

Constructor Detail

AFSocketback to summary
protected AFSocket(final AFSocketImpl<A> impl, AFSocketAddressFromHostname<A> afh) throws SocketException

Creates a new AFSocket instance.

Parameters
impl:AFSocketImpl<A>

The corresponding SocketImpl class.

afh:AFSocketAddressFromHostname<A>

The conversion helper to get a socket address from an encoded hostname.

Annotations
@SuppressFBWarnings:CT_CONSTRUCTOR_THROW
Exceptions
SocketException:
on error.

Method Detail

addCloseableback to summary
public final void addCloseable(Closeable closeable)

Registers a Closeable that should be closed when this socket is closed.

Parameters
closeable:Closeable

The closeable.

bindback to summary
public final void bind(SocketAddress bindpoint) throws IOException

Overrides java.net.Socket.bind.

Not supported, since it's not necessary for client sockets.

Parameters
bindpoint:SocketAddress

Doc from java.net.Socket.bind.

the SocketAddress to bind to

Annotations
@Override
Exceptions
IOException:

Doc from java.net.Socket.bind.

if the bind operation fails, the socket is already bound or the socket is closed.

See Also
AFServerSocket
capabilitiesback to summary
private static synchronized int capabilities()
checkConnectionClosedback to summary
public boolean checkConnectionClosed() throws IOException

Probes the status of the socket connection. This usually involves checking for isConnected(), and if assumed connected, also sending a zero-length message to the remote.

Returns:boolean

true if the connection is known to be closed, false if the connection is open/not closed or the condition is unknown.

Exceptions
IOException:
on an unexpected error.
closeback to summary
public final synchronized void close() throws IOException

Overrides java.net.Socket.close.

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
connectback to summary
public final void connect(SocketAddress endpoint) throws IOException

Overrides java.net.Socket.connect.

Doc from java.net.Socket.connect.

Connects this socket to the server.

If the connection cannot be established, then the socket is closed, and an IOException is thrown.

This method is interruptible in the following circumstances:

  1. The socket is associated with a SocketChannel. In that case, interrupting a thread establishing a connection will close the underlying channel and cause this method to throw ClosedByInterruptException with the interrupt status set.
  2. The socket uses the system-default socket implementation and a virtual thread is establishing a connection. In that case, interrupting the virtual thread will cause it to wakeup and close the socket. This method will then throw SocketException with the interrupt status set.
Parameters
endpoint:SocketAddress

the SocketAddress

Annotations
@Override
Exceptions
IOException:
if an error occurs during the connection, the socket is already connected or the socket is closed
connectback to summary
public final void connect(SocketAddress endpoint, int timeout) throws IOException

Overrides java.net.Socket.connect.

Doc from java.net.Socket.connect.

Connects this socket to the server with a specified timeout value. A timeout of zero is interpreted as an infinite timeout. The connection will then block until established or an error occurs.

If the connection cannot be established, or the timeout expires before the connection is established, then the socket is closed, and an IOException is thrown.

This method is interruptible in the following circumstances:

  1. The socket is associated with a SocketChannel. In that case, interrupting a thread establishing a connection will close the underlying channel and cause this method to throw ClosedByInterruptException with the interrupt status set.
  2. The socket uses the system-default socket implementation and a virtual thread is establishing a connection. In that case, interrupting the virtual thread will cause it to wakeup and close the socket. This method will then throw SocketException with the interrupt status set.
Parameters
endpoint:SocketAddress

the SocketAddress

timeout:int

the timeout value to be used in milliseconds.

Annotations
@Override
Exceptions
IOException:
if an error occurs during the connection, the socket is already connected or the socket is closed
connect0back to summary
pack-priv final boolean connect0(SocketAddress endpoint, int timeout) throws IOException
connectHookback to summary
public final AFSocket<A> connectHook(SocketAddressFilter hook)

Sets the hook for any subsequent call to connect(SocketAddress) or connect(SocketAddress, int) to be the given function. The function can monitor events or even alter the target address.

Parameters
hook:SocketAddressFilter

The function that gets called for each connect call.

Returns:AFSocket<A>

This instance.

connectToback to summary
protected static final <A extends AFSocketAddress> @NonNull AFSocket<A> connectTo(AFSocket.Constructor<A> constr, A addr) throws IOException

Creates a new AFSocket and connects it to the given AFSocketAddress.

Parameters
<A>
The corresponding address type.
constr:AFSocket.Constructor<A>

The implementation's AFSocket constructor

addr:A

The address to connect to.

Returns:@NonNull AFSocket<A>

A new, connected socket.

Exceptions
IOException:
if the operation fails.
connectToback to summary
public static final <A extends AFSocketAddress> AFSocket<?> connectTo(@NonNull A addr) throws IOException

Creates a new AFSocket and connects it to the given AFSocketAddress using the default implementation suited for that address type.

Parameters
<A>
The corresponding address type.
addr:@NonNull A

The address to connect to.

Returns:AFSocket<?>

A new, connected socket.

Exceptions
IOException:
if the operation fails.
ensureAncillaryReceiveBufferSizeback to summary
public final void ensureAncillaryReceiveBufferSize(int minSize)

Implements org.newsclub.net.unix.AFSocketExtensions.ensureAncillaryReceiveBufferSize.

Doc from org.newsclub.net.unix.AFSocketExtensions.ensureAncillaryReceiveBufferSize.

Ensures a minimum ancillary receive buffer size.

Parameters
minSize:int

The minimum size (in bytes).

Annotations
@Override
ensureSupportedback to summary
public static void ensureSupported() throws UnsupportedOperationException

Checks if AFSockets are supported by the current Java VM. If not, an UnsupportedOperationException is thrown.

Exceptions
UnsupportedOperationException:
if not supported.
ensureUnsafeSupportedback to summary
public static final void ensureUnsafeSupported() throws IOException

Checks if the current environment (system platform, native library, etc.) supports "unsafe" operations (as controlled via the AFSocketCapability#CAPABILITY_UNSAFE capability). If supported, the method returns normally. If not supported, an IOException is thrown.

Exceptions
IOException:
if "unsafe" operations are not supported.
See Also
Unsafe
forceConnectAddressback to summary
public final AFSocket<A> forceConnectAddress(SocketAddress endpoint)

Forces the address to be used for any subsequent call to connect(SocketAddress) to be the given one, regardless of what'll be passed there.

Parameters
endpoint:SocketAddress

The forced endpoint address.

Returns:AFSocket<A>

This instance.

getAFImplback to summary
pack-priv final AFSocketImpl<A> getAFImpl()
getAFImplback to summary
pack-priv final AFSocketImpl<A> getAFImpl(boolean createSocket)
getAncillaryReceiveBufferSizeback to summary
public final int getAncillaryReceiveBufferSize()

Implements org.newsclub.net.unix.AFSocketExtensions.getAncillaryReceiveBufferSize.

Doc from org.newsclub.net.unix.AFSocketExtensions.getAncillaryReceiveBufferSize.

Returns the size of the receive buffer for ancillary messages (in bytes).

Returns:int

The size.

Annotations
@Override
getChannelback to summary
public AFSocketChannel<A> getChannel()

Overrides java.net.Socket.getChannel.

Doc from java.net.Socket.getChannel.

Returns the unique SocketChannel object associated with this socket, if any.

A socket will have a channel if, and only if, the channel itself was created via the SocketChannel.open or ServerSocketChannel.accept methods.

Returns:AFSocketChannel<A>

the socket channel associated with this socket, or null if this socket was not created for a channel

Annotations
@SuppressFBWarnings:EI_EXPOSE_REP
@Override
getFileDescriptorback to summary
public final FileDescriptor getFileDescriptor() throws IOException

Implements org.newsclub.net.unix.FileDescriptorAccess.getFileDescriptor.

Doc from org.newsclub.net.unix.FileDescriptorAccess.getFileDescriptor.

Returns the corresponding FileDescriptor.

Returns:FileDescriptor

The corresponding FileDescriptor.

Annotations
@Override
Exceptions
IOException:
on error.
getImplExtensionsback to summary
protected final AFSocketImplExtensions<A> getImplExtensions()

Returns the internal helper instance for address-specific extensions.

Returns:AFSocketImplExtensions<A>

The helper instance.

Exceptions
UnsupportedOperationException:
if such extensions are not supported for this address type.
getInputStreamback to summary
public final AFInputStream getInputStream() throws IOException

Overrides java.net.Socket.getInputStream.

Doc from java.net.Socket.getInputStream.

Returns an input stream for this socket.

If this socket has an associated channel then the resulting input stream delegates all of its operations to the channel. If the channel is in non-blocking mode then the input stream's read operations will throw an java.nio.channels.IllegalBlockingModeException.

Reading from the input stream is interruptible in the following circumstances:

  1. The socket is associated with a SocketChannel. In that case, interrupting a thread reading from the input stream will close the underlying channel and cause the read method to throw ClosedByInterruptException with the interrupt status set.
  2. The socket uses the system-default socket implementation and a virtual thread is reading from the input stream. In that case, interrupting the virtual thread will cause it to wakeup and close the socket. The read method will then throw SocketException with the interrupt status set.

Under abnormal conditions the underlying connection may be broken by the remote host or the network software (for example a connection reset in the case of TCP connections). When a broken connection is detected by the network software the following applies to the returned input stream :-

  • The network software may discard bytes that are buffered by the socket. Bytes that aren't discarded by the network software can be read using read.

  • If there are no bytes buffered on the socket, or all buffered bytes have been consumed by read, then all subsequent calls to read will throw an IOException.

  • If there are no bytes buffered on the socket, and the socket has not been closed using close, then available will return 0.

Closing the returned InputStream will close the associated socket.

Returns:AFInputStream

an input stream for reading bytes from this socket.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs when creating the input stream, the socket is closed, the socket is not connected, or the socket input has been shutdown using shutdownInput()
getLoadedLibraryback to summary
public static final String getLoadedLibrary()

Returns an identifier of the loaded native library, or null if the library hasn't been loaded yet. The identifier is useful mainly for debugging purposes.

Returns:String

The identifier of the loaded junixsocket-native library, or null.

getLocalSocketAddressback to summary
public final A getLocalSocketAddress()

Overrides java.net.Socket.getLocalSocketAddress.

Implements org.newsclub.net.unix.AFSomeSocketThing.getLocalSocketAddress.

Doc from org.newsclub.net.unix.AFSomeSocketThing.getLocalSocketAddress.

Returns the socket's local socket address, or null if unavailable or if there was a problem retrieving it.

Returns:A

The local socket address, or null.

Annotations
@SuppressWarnings:null
@Override
getOutputStreamback to summary
public final AFOutputStream getOutputStream() throws IOException

Overrides java.net.Socket.getOutputStream.

Doc from java.net.Socket.getOutputStream.

Returns an output stream for this socket.

If this socket has an associated channel then the resulting output stream delegates all of its operations to the channel. If the channel is in non-blocking mode then the output stream's write operations will throw an java.nio.channels.IllegalBlockingModeException.

Writing to the output stream is interruptible in the following circumstances:

  1. The socket is associated with a SocketChannel. In that case, interrupting a thread writing to the output stream will close the underlying channel and cause the write method to throw ClosedByInterruptException with the interrupt status set.
  2. The socket uses the system-default socket implementation and a virtual thread is writing to the output stream. In that case, interrupting the virtual thread will cause it to wakeup and close the socket. The write method will then throw SocketException with the interrupt status set.

Closing the returned OutputStream will close the associated socket.

Returns:AFOutputStream

an output stream for writing bytes to this socket.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs when creating the output stream, the socket is not connected or the socket is closed.
getRemoteSocketAddressback to summary
public final synchronized A getRemoteSocketAddress()

Overrides java.net.Socket.getRemoteSocketAddress.

Implements org.newsclub.net.unix.AFSomeSocket.getRemoteSocketAddress.

Doc from org.newsclub.net.unix.AFSomeSocket.getRemoteSocketAddress.

Returns the socket's remote socket address, or null if unavailable/not connected, or if there was a problem retrieving it.

Returns:A

The remote socket address, or null.

Annotations
@SuppressWarnings:null
@Override
getVersionback to summary
public static final String getVersion()

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.

Returns:String

String The version identifier, or null if it could not be determined.

See Also
supports(AFSocketCapability)
initCapabilitiesback to summary
private static int initCapabilities()
internalDummyBindback to summary
pack-priv final void internalDummyBind() throws IOException
internalDummyConnectback to summary
pack-priv final void internalDummyConnect() throws IOException
isBoundback to summary
public final boolean isBound()

Overrides java.net.Socket.isBound.

Doc from java.net.Socket.isBound.

Returns the binding state of the socket.

Note

Closing a socket doesn't clear its binding state, which means this method will return true for a closed socket (see isClosed()) if it was successfully bound prior to being closed.

Returns:boolean

true if the socket was successfully bound to an address

Annotations
@Override
isCapDisabledback to summary
private static boolean isCapDisabled(AFSocketCapability cap)
isClosedback to summary
public final boolean isClosed()

Overrides java.net.Socket.isClosed.

Doc from java.net.Socket.isClosed.

Returns the closed state of the socket.

Returns:boolean

true if the socket has been closed

Annotations
@Override
isConnectedback to summary
public final boolean isConnected()

Overrides java.net.Socket.isConnected.

Doc from java.net.Socket.isConnected.

Returns the connection state of the socket.

Note

Closing a socket doesn't clear its connection state, which means this method will return true for a closed socket (see isClosed()) if it was successfully connected prior to being closed.

Returns:boolean

true if the socket was successfully connected to a server

Annotations
@Override
isRunningOnAndroidback to summary
public static boolean isRunningOnAndroid()

Checks if we're running on Android (as far as junixsocket is concerned).

Returns:boolean

true if running on Android.

isSupportedback to summary
public static boolean isSupported()

Returns true iff AFSockets are supported by the current Java VM. To support AFSockets, a custom JNI library must be loaded that is supplied with junixsocket.

Returns:boolean

true iff supported.

newChannelback to summary
protected abstract AFSocketChannel<A> newChannel()

Creates a new AFSocketChannel for this socket.

Returns:AFSocketChannel<A>

The new instance.

newInstanceback to summary
pack-priv static <A extends AFSocketAddress> AFSocket<A> newInstance(AFSocket.Constructor<A> constr, AFSocketFactory<A> sf, FileDescriptor fdObj, int localPort, int remotePort) throws IOException
newInstanceback to summary
protected static final <A extends AFSocketAddress> AFSocket<A> newInstance(AFSocket.Constructor<A> constr, AFSocketFactory<A> factory) throws SocketException

Creates a new, unbound AFSocket. This "default" implementation is a bit "lenient" with respect to the specification. In particular, we may ignore calls to Socket#getTcpNoDelay() and Socket#setTcpNoDelay(boolean).

Parameters
<A>
The corresponding address type.
constr:AFSocket.Constructor<A>

The implementation's AFSocket constructor

factory:AFSocketFactory<A>

The corresponding socket factory, or null.

Returns:AFSocket<A>

A new, unbound socket.

Exceptions
SocketException:
if the operation fails.
newInstance0back to summary
private static <A extends AFSocketAddress> @NonNull AFSocket<A> newInstance0(AFSocket.Constructor<A> constr, FileDescriptor fdObj, AFSocketFactory<A> factory) throws SocketException
preprocessSocketAddressback to summary
private AFSocketAddress preprocessSocketAddress(SocketAddress endpoint) throws SocketException
removeCloseableback to summary
public final void removeCloseable(Closeable closeable)

Unregisters a previously registered Closeable.

Parameters
closeable:Closeable

The closeable.

setAncillaryReceiveBufferSizeback to summary
public final void setAncillaryReceiveBufferSize(int size)

Implements org.newsclub.net.unix.AFSocketExtensions.setAncillaryReceiveBufferSize.

Doc from org.newsclub.net.unix.AFSocketExtensions.setAncillaryReceiveBufferSize.

Sets the size of the receive buffer for ancillary messages (in bytes). To disable handling ancillary messages, set it to 0 (default).

Parameters
size:int

The size.

Annotations
@Override
setShutdownOnCloseback to summary
public void setShutdownOnClose(boolean enabled)

Implements org.newsclub.net.unix.AFSomeSocketThing.setShutdownOnClose.

Doc from org.newsclub.net.unix.AFSomeSocketThing.setShutdownOnClose.

Configures whether the socket should be shutdown upon close(), which is the default.

Parameters
enabled:boolean

true if enabled.

Annotations
@Override
socketAddressClassback to summary
protected final Class<? extends AFSocketAddress> socketAddressClass()

Returns the AFSocketAddress type supported by this socket.

Returns:Class<? extends AFSocketAddress>

The supported AFSocketAddress.

supportsback to summary
public static final boolean supports(AFUNIXSocketCapability capability)

Deprecated

Checks if the current environment (system platform, native library, etc.) supports a given junixsocket capability. Deprecated. Please use supports(AFSocketCapability) instead.

Note

The result may or may not be cached from a previous call or from a check upon initialization.

Parameters
capability:AFUNIXSocketCapability

The capability.

Returns:boolean

true if supported.

Annotations
@Deprecated
See Also
supports(AFSocketCapability)
supportsback to summary
public static final boolean supports(AFSocketCapability 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.

Parameters
capability:AFSocketCapability

The capability.

Returns:boolean

true if supported.

toStringback to summary
public final String toString()

Overrides java.net.Socket.toString.

Doc from java.net.Socket.toString.

Converts this socket to a String.

Returns:String

a string representation of this socket.

Annotations
@Override
toStringSuffixback to summary
pack-priv final String toStringSuffix()
org.newsclub.net.unix back to summary

public Interface AFSocket.Constructor<A extends AFSocketAddress>

Annotations
@FunctionalInterface
Type Parameters
<A>
The concrete AFSocketAddress that is supported by this type.

The reference to the constructor of an AFSocket subclass.

Method Summary

Modifier and TypeMethod and Description
public @NonNull AFSocket<A>

Returns:

The instance.
newInstance
(FileDescriptor
The file descriptor.
fdObj
,
AFSocketFactory<A>
The socket factory instance.
factory
)

Constructs a new AFSocket subclass instance.

Method Detail

newInstanceback to summary
public @NonNull AFSocket<A> newInstance(FileDescriptor fdObj, AFSocketFactory<A> factory) throws SocketException

Constructs a new AFSocket subclass instance.

Parameters
fdObj:FileDescriptor

The file descriptor.

factory:AFSocketFactory<A>

The socket factory instance.

Returns:@NonNull AFSocket<A>

The instance.

Exceptions
SocketException:
on error.