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

public final Class AFUNIXSocket

extends AFSocket<AFUNIXSocketAddress>
implements AFUNIXSocketExtensions
Class Inheritance
All Implemented Interfaces
org.newsclub.net.unix.AFUNIXSocketExtensions, org.newsclub.net.unix.AFSocketExtensions
Imports
java.io.DataInputStream, .DataOutputStream, .FileDescriptor, .IOException, java.net.Socket, .SocketException, java.nio.ByteBuffer, .ByteOrder, java.nio.channels.SocketChannel, java.util.concurrent.atomic.AtomicBoolean, org.eclipse.jdt.annotation.NonNull

Implementation of an AF_UNIX domain socket.
Author
Christian Kohlschütter

Field Summary

Modifier and TypeField and Description
private static final AFSocket.Constructor<AFUNIXSocketAddress>
Inherited from org.newsclub.net.unix.AFSocket:
loadedLibraryPROP_LIBRARY_DISABLE_CAPABILITY_PREFIX

Constructor Summary

AccessConstructor and Description
private
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
clearReceivedFileDescriptors()

Implements org.newsclub.net.unix.AFUNIXSocketExtensions.clearReceivedFileDescriptors.

Clears the queue of incoming FileDescriptors that were sent as ancillary messages.

public static AFUNIXSocket

Returns:

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

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

public AFUNIXSocketChannel
getChannel()

Overrides org.newsclub.net.unix.AFSocket.getChannel.

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

public AFUNIXSocketCredentials
getPeerCredentials()

Implements org.newsclub.net.unix.AFUNIXSocketExtensions.getPeerCredentials.

Retrieves the "peer credentials" for this connection.

public FileDescriptor[]
getReceivedFileDescriptors()

Implements org.newsclub.net.unix.AFUNIXSocketExtensions.getReceivedFileDescriptors.

Retrieves an array of incoming FileDescriptors that were sent as ancillary messages, along with a call to InputStream#read(), etc.

Note

Another call to this method will not return the same file descriptors again (most likely, an empty array will be returned).

public boolean
hasOutboundFileDescriptors()

Implements org.newsclub.net.unix.AFUNIXSocketExtensions.hasOutboundFileDescriptors.

Returns true if there are pending file descriptors to be sent as part of an ancillary message.

public static boolean

Returns:

true iff supported.
isSupported
()

Hides org.newsclub.net.unix.AFSocket.isSupported.

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

public static void
main(String[]
ignored.
args
)

Very basic self-test function.

private static void
protected AFUNIXSocketChannel
newChannel()

Implements abstract org.newsclub.net.unix.AFSocket.newChannel.

Creates a new AFSocketChannel for this socket.

public static AFUNIXSocket

Returns:

A new, unbound socket.
newInstance
()

Creates a new, unbound AFSocket.

pack-priv static AFUNIXSocket
newInstance(FileDescriptor fdObj, int localPort, int remotePort)

pack-priv static AFUNIXSocket
pack-priv static AFUNIXSocket
public static AFUNIXSocket

Returns:

A new, unbound socket.
newStrictInstance
()

Creates a new, unbound, "strict" AFSocket.

public void
setOutboundFileDescriptors(FileDescriptor...
The file descriptors, or null if none.
fdescs
)

Implements org.newsclub.net.unix.AFUNIXSocketExtensions.setOutboundFileDescriptors.

Sets a list of FileDescriptors that should be sent as an ancillary message along with the next write.

Inherited from org.newsclub.net.unix.AFSocket:
addCloseablebindcheckConnectionClosedcloseconnectconnectconnect0connectHookconnectToconnectToensureAncillaryReceiveBufferSizeensureSupportedensureUnsafeSupportedforceConnectAddressgetAFImplgetAFImplgetAncillaryReceiveBufferSizegetFileDescriptorgetImplExtensionsgetInputStreamgetLoadedLibrarygetLocalSocketAddressgetOutputStreamgetRemoteSocketAddressgetVersioninternalDummyBindinternalDummyConnectisBoundisClosedisConnectedisRunningOnAndroidnewInstancenewInstanceremoveCloseablesetAncillaryReceiveBufferSizesetShutdownOnClosesocketAddressClasssupportssupportstoStringtoStringSuffix

Field Detail

CONSTRUCTOR_STRICTback to summary
private static final AFSocket.Constructor<AFUNIXSocketAddress> CONSTRUCTOR_STRICT

Constructor Detail

AFUNIXSocketback to summary
private AFUNIXSocket(AFSocketImpl<AFUNIXSocketAddress> impl, AFSocketFactory<AFUNIXSocketAddress> factory) throws SocketException
AFUNIXSocketback to summary
pack-priv AFUNIXSocket(FileDescriptor fd, AFSocketFactory<AFUNIXSocketAddress> factory) throws SocketException

Method Detail

clearReceivedFileDescriptorsback to summary
public void clearReceivedFileDescriptors()

Implements org.newsclub.net.unix.AFUNIXSocketExtensions.clearReceivedFileDescriptors.

Doc from org.newsclub.net.unix.AFUNIXSocketExtensions.clearReceivedFileDescriptors.

Clears the queue of incoming FileDescriptors that were sent as ancillary messages.

Annotations
@Override
connectToback to summary
public static AFUNIXSocket connectTo(AFUNIXSocketAddress addr) throws IOException

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

Parameters
addr:AFUNIXSocketAddress

The address to connect to.

Returns:AFUNIXSocket

A new, connected socket.

Exceptions
IOException:
if the operation fails.
getChannelback to summary
public AFUNIXSocketChannel getChannel()

Overrides org.newsclub.net.unix.AFSocket.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:AFUNIXSocketChannel

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

Annotations
@Override
getPeerCredentialsback to summary
public AFUNIXSocketCredentials getPeerCredentials() throws IOException

Implements org.newsclub.net.unix.AFUNIXSocketExtensions.getPeerCredentials.

Doc from org.newsclub.net.unix.AFUNIXSocketExtensions.getPeerCredentials.

Retrieves the "peer credentials" for this connection. These credentials may be useful to authenticate the other end of the socket (client or server). Depending on the socket/connection/environment, you may not receive any or all credentials. For example, on Linux, AFUNIXDatagramSocket and AFUNIXDatagramChannel may not be able to retrieve credentials at all.

Returns:AFUNIXSocketCredentials

The peer's credentials, or null if they couldn't be retrieved.

Annotations
@Override
Exceptions
IOException:
If there was an error returning these credentials.
getReceivedFileDescriptorsback to summary
public FileDescriptor[] getReceivedFileDescriptors() throws IOException

Implements org.newsclub.net.unix.AFUNIXSocketExtensions.getReceivedFileDescriptors.

Doc from org.newsclub.net.unix.AFUNIXSocketExtensions.getReceivedFileDescriptors.

Retrieves an array of incoming FileDescriptors that were sent as ancillary messages, along with a call to InputStream#read(), etc.

Note

Another call to this method will not return the same file descriptors again (most likely, an empty array will be returned).

Returns:FileDescriptor[]

The file descriptors, or an empty array if none were available.

Annotations
@Override
Exceptions
IOException:
if the operation fails.
hasOutboundFileDescriptorsback to summary
public boolean hasOutboundFileDescriptors()

Implements org.newsclub.net.unix.AFUNIXSocketExtensions.hasOutboundFileDescriptors.

Doc from org.newsclub.net.unix.AFUNIXSocketExtensions.hasOutboundFileDescriptors.

Returns true if there are pending file descriptors to be sent as part of an ancillary message.

Returns:boolean

true if there are file descriptors pending.

Annotations
@Override
isSupportedback to summary
public static boolean isSupported()

Hides org.newsclub.net.unix.AFSocket.isSupported.

Returns true iff AFUNIXSockets are supported by the current Java VM. To support AFSockets, 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 AFSocket#isSupported() and AFSocket#supports(AFSocketCapability) with AFSocketCapability#CAPABILITY_UNIX_DOMAIN.

Returns:boolean

true iff supported.

mainback to summary
public static void main(String[] args)

Very basic self-test function. Prints "supported" and "capabilities" status to System.out.

Parameters
args:String[]

ignored.

miniSelftestback to summary
private static void miniSelftest()
newChannelback to summary
protected AFUNIXSocketChannel newChannel()

Implements abstract org.newsclub.net.unix.AFSocket.newChannel.

Doc from org.newsclub.net.unix.AFSocket.newChannel.

Creates a new AFSocketChannel for this socket.

Returns:AFUNIXSocketChannel

The new instance.

Annotations
@Override
newInstanceback to summary
public static AFUNIXSocket newInstance() throws IOException

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

Returns:AFUNIXSocket

A new, unbound socket.

Exceptions
IOException:
if the operation fails.
newInstanceback to summary
pack-priv static AFUNIXSocket newInstance(FileDescriptor fdObj, int localPort, int remotePort) throws IOException
newInstanceback to summary
pack-priv static AFUNIXSocket newInstance(AFUNIXSocketFactory factory) throws SocketException
newLenientInstanceback to summary
pack-priv static AFUNIXSocket newLenientInstance() throws IOException
newStrictInstanceback to summary
public static AFUNIXSocket newStrictInstance() throws IOException

Creates a new, unbound, "strict" AFSocket. This call uses an implementation that tries to be closer to the specification than newInstance(), at least for some cases.

Returns:AFUNIXSocket

A new, unbound socket.

Exceptions
IOException:
if the operation fails.
setOutboundFileDescriptorsback to summary
public void setOutboundFileDescriptors(FileDescriptor... fdescs) throws IOException

Implements org.newsclub.net.unix.AFUNIXSocketExtensions.setOutboundFileDescriptors.

Doc from org.newsclub.net.unix.AFUNIXSocketExtensions.setOutboundFileDescriptors.

Sets a list of FileDescriptors that should be sent as an ancillary message along with the next write.

Important Note

There can only be one set of file descriptors active until the write completes. The socket also needs to be connected for this operation to succeed. It is also important to know that there may be an upper limit imposed by the operation system as to how many file descriptors can be sent at once. Linux, for example, may support up to 253. If the number of file descriptors exceeds the limit, an exception may be thrown when sending data along with the ancillary message containing the file descriptors.

Parameters
fdescs:FileDescriptor[]

The file descriptors, or null if none.

Annotations
@Override
Exceptions
IOException:
if the operation fails.