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

pack-priv final Class NativeUnixSocket

extends Object
Class Inheritance
Imports
java.io.Closeable, .FileDescriptor, .IOException, java.lang.ProcessBuilder.Redirect, java.net.InetSocketAddress, .ServerSocket, .Socket, .SocketAddress, .SocketException, java.nio.ByteBuffer, java.nio.channels.SelectionKey, java.nio.channels.spi.AbstractSelectableChannel, java.util.concurrent.atomic.AtomicBoolean, org.newsclub.net.unix.AFSelector.PollFd, com.kohlschutter.annotations.compiletime.ExcludeFromCodeCoverageGeneratedReport, .SuppressFBWarnings

JNI connector to native JNI C code.
Author
Christian Kohlschütter

Field Summary

Modifier and TypeField and Description
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
private static Throwable
private static final AtomicBoolean
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
OPT_NON_SOCKET

Indicator that the handle isn't referring to a socket but some other file descriptor.

pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static native boolean
accept(ByteBuffer sockaddr, int sockaddrLen, FileDescriptor fdServer, FileDescriptor fd, long inode, int timeout)

pack-priv static native int
pack-priv static native void
pack-priv static native int
pack-priv static native long
bind(ByteBuffer sockaddr, int sockaddrLen, FileDescriptor fd, int options)

pack-priv static native int
bytesToSockAddr(int domain, ByteBuffer sockAddrDirectBuf, byte[] address)

pack-priv static native int
pack-priv static native int

Returns:

0 = non-blocking, 1 = blocking, 2 = indeterminate (needs reconfiguration)
checkBlocking
(FileDescriptor
The file descriptor to check
fd
)

Checks if the given file descriptor describes a blocking socket.

pack-priv static native void
pack-priv static native void
configureBlocking(FileDescriptor fd, boolean blocking)

pack-priv static native boolean
connect(ByteBuffer sockaddr, int sockaddrLen, FileDescriptor fd, long inode)

pack-priv static native void
pack-priv static native void
createSocket(FileDescriptor fdesc, int domain, int type)

pack-priv static native Socket
pack-priv static native void
pack-priv static native void
pack-priv static native void
pack-priv static native FileDescriptor
pack-priv static void
pack-priv static native boolean
pack-priv static native int
pack-priv static native <T> T
getSocketOption(FileDescriptor fd, int level, int optionName, Class<T> valueType)

pack-priv static native int
pack-priv static native void
init()

pack-priv static native void
initFD(FileDescriptor fdesc, int fd)

pack-priv static native boolean
initPipe(FileDescriptor source, FileDescriptor sink, boolean selectable)

pack-priv static void
pack-priv static native ProcessBuilder.Redirect
pack-priv static native void
initServerImpl(ServerSocket serverSocket, AFSocketImpl<?> impl)

pack-priv static boolean
pack-priv static native void
listen(FileDescriptor fd, int backlog)

pack-priv static native int
pack-priv static native void
noop()

Can be used to check (without side-effects) if the library has been loaded.

pack-priv static native AFUNIXSocketCredentials
pack-priv static native int
poll(AFSelector.PollFd pollFd, int timeout)

pack-priv static native Class<?>
pack-priv static native int

Returns:

The number of bytes read, -1 if nothing could be read, or the byte itself iff buf was null.
read
(FileDescriptor
The corresponding file descriptor.
fd
,
byte[]
The buffer to read into, or null if a single byte should be read.
buf
,
int
The buffer offset.
off
,
int
The maximum number of bytes to read. Must be 1 if buf is null.
len
,
int
Options.
options
,
AncillaryDataSupport
The ancillary data support instance, or null.
ancillaryDataSupport
,
int timeoutMillis)

Reads data from an AFSocketImpl.

pack-priv static native int
receive(FileDescriptor fd, ByteBuffer directBuffer, int offset, int length, ByteBuffer directSocketAddressOut, int options, AncillaryDataSupport ancillaryDataSupport, int timeoutMillis)

pack-priv static Throwable
pack-priv static native int
send(FileDescriptor fd, ByteBuffer directBuffer, int offset, int length, ByteBuffer directSocketAddress, int addrLen, int options, AncillaryDataSupport ancillaryDataSupport)

pack-priv static void
setLoaded(boolean successful)

pack-priv static native void
setPort(SocketAddress addr, int port)

pack-priv static void
setPort1(SocketAddress addr, int port)

pack-priv static native void
setSocketOption(FileDescriptor fd, int level, int optionName, Object value)

pack-priv static native void
setSocketOptionInt(FileDescriptor fd, int optionId, int value)

pack-priv static native void
shutdown(FileDescriptor fd, int mode)

pack-priv static native int
sockAddrLength(int domain)

pack-priv static native int
pack-priv static native int
pack-priv static native byte[]
sockAddrToBytes(int domain, ByteBuffer sockAddrDirect)

pack-priv static native void
socketPair(int domain, int type, FileDescriptor fd, FileDescriptor fd2)

pack-priv static native int
pack-priv static native byte[]
sockname(int domain, FileDescriptor fd, boolean peer)

pack-priv static native int
sockTypeToNative(int type)

pack-priv static native int
pack-priv static native byte[]
tipcGetLinkName(int peer, int bearerId)

pack-priv static native byte[]
tipcGetNodeId(int peer)

private static void
pack-priv static UnsupportedOperationException
pack-priv static native int
pack-priv static native int

Returns:

The number of bytes written (which could be 0).
write
(FileDescriptor
The corresponding file descriptor.
fd
,
byte[]
The buffer to write from, or null if a single byte should be written.
buf
,
int
The buffer offset, or the byte to write if buf is null.
off
,
int
The number of bytes to write. Must be 1 if buf is null.
len
,
int
Options.
options
,
AncillaryDataSupport
The ancillary data support instance, or null.
ancillaryDataSupport
)

Writes data to an AFSocketImpl.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BIND_OPT_REUSEback to summary
pack-priv static final int BIND_OPT_REUSE
DOMAIN_GENERICback to summary
pack-priv static final int DOMAIN_GENERIC
DOMAIN_SYSTEMback to summary
pack-priv static final int DOMAIN_SYSTEM
DOMAIN_TIPCback to summary
pack-priv static final int DOMAIN_TIPC
DOMAIN_UNIXback to summary
pack-priv static final int DOMAIN_UNIX
DOMAIN_VSOCKback to summary
pack-priv static final int DOMAIN_VSOCK
initErrorback to summary
private static Throwable initError
Annotations
@SuppressWarnings:StaticAssignmentOfThrowable
LOADEDback to summary
private static final AtomicBoolean LOADED
OPT_DGRAM_MODEback to summary
pack-priv static final int OPT_DGRAM_MODE
OPT_LOOKUP_SENDERback to summary
pack-priv static final int OPT_LOOKUP_SENDER
OPT_NON_BLOCKINGback to summary
pack-priv static final int OPT_NON_BLOCKING
OPT_NON_SOCKETback to summary
pack-priv static final int OPT_NON_SOCKET

Indicator that the handle isn't referring to a socket but some other file descriptor.

OPT_PEEKback to summary
pack-priv static final int OPT_PEEK
SHUT_RDback to summary
pack-priv static final int SHUT_RD
SHUT_RD_WRback to summary
pack-priv static final int SHUT_RD_WR
SHUT_WRback to summary
pack-priv static final int SHUT_WR
SOCK_DGRAMback to summary
pack-priv static final int SOCK_DGRAM
SOCK_RAWback to summary
pack-priv static final int SOCK_RAW
SOCK_RDMback to summary
pack-priv static final int SOCK_RDM
SOCK_SEQPACKETback to summary
pack-priv static final int SOCK_SEQPACKET
SOCK_STREAMback to summary
pack-priv static final int SOCK_STREAM
SOCKETSTATUS_BOUNDback to summary
pack-priv static final int SOCKETSTATUS_BOUND
SOCKETSTATUS_CONNECTEDback to summary
pack-priv static final int SOCKETSTATUS_CONNECTED
SOCKETSTATUS_INVALIDback to summary
pack-priv static final int SOCKETSTATUS_INVALID
SOCKETSTATUS_UNKNOWNback to summary
pack-priv static final int SOCKETSTATUS_UNKNOWN

Constructor Detail

NativeUnixSocketback to summary
private NativeUnixSocket()
Annotations
@ExcludeFromCodeCoverageGeneratedReport
reason:unreachable

Method Detail

acceptback to summary
pack-priv static native boolean accept(ByteBuffer sockaddr, int sockaddrLen, FileDescriptor fdServer, FileDescriptor fd, long inode, int timeout) throws IOException
ancillaryBufMinLenback to summary
pack-priv static native int ancillaryBufMinLen()
attachCloseableback to summary
pack-priv static native void attachCloseable(FileDescriptor fdesc, Closeable closeable) throws SocketException
availableback to summary
pack-priv static native int available(FileDescriptor fd, ByteBuffer buf) throws IOException
bindback to summary
pack-priv static native long bind(ByteBuffer sockaddr, int sockaddrLen, FileDescriptor fd, int options) throws IOException
bytesToSockAddrback to summary
pack-priv static native int bytesToSockAddr(int domain, ByteBuffer sockAddrDirectBuf, byte[] address)
capabilitiesback to summary
pack-priv static native int capabilities()
checkBlockingback to summary
pack-priv static native int checkBlocking(FileDescriptor fd) throws IOException

Checks if the given file descriptor describes a blocking socket.

Parameters
fd:FileDescriptor

The file descriptor to check

Returns:int

0 = non-blocking, 1 = blocking, 2 = indeterminate (needs reconfiguration)

Exceptions
IOException:
on error.
closeback to summary
pack-priv static native void close(FileDescriptor fd) throws IOException
configureBlockingback to summary
pack-priv static native void configureBlocking(FileDescriptor fd, boolean blocking) throws IOException
connectback to summary
pack-priv static native boolean connect(ByteBuffer sockaddr, int sockaddrLen, FileDescriptor fd, long inode) throws IOException
copyFileDescriptorback to summary
pack-priv static native void copyFileDescriptor(FileDescriptor source, FileDescriptor target) throws IOException
createSocketback to summary
pack-priv static native void createSocket(FileDescriptor fdesc, int domain, int type) throws IOException
currentRMISocketback to summary
pack-priv static native Socket currentRMISocket()
deregisterSelectionKeyback to summary
pack-priv static native void deregisterSelectionKey(AbstractSelectableChannel chann, SelectionKey key)
destroyback to summary
pack-priv static native void destroy() throws Exception
Annotations
@SuppressFBWarnings:THROWS_METHOD_THROWS_CLAUSE_BASIC_EXCEPTION
disconnectback to summary
pack-priv static native void disconnect(FileDescriptor fd) throws IOException
duplicateback to summary
pack-priv static native FileDescriptor duplicate(FileDescriptor fdSource, FileDescriptor fdTarget) throws IOException
ensureSupportedback to summary
pack-priv static void ensureSupported() throws UnsupportedOperationException
finishConnectback to summary
pack-priv static native boolean finishConnect(FileDescriptor fd) throws IOException
getFDback to summary
pack-priv static native int getFD(FileDescriptor fdesc) throws IOException
getSocketOptionback to summary
pack-priv static native <T> T getSocketOption(FileDescriptor fd, int level, int optionName, Class<T> valueType) throws IOException
getSocketOptionIntback to summary
pack-priv static native int getSocketOptionInt(FileDescriptor fd, int optionId) throws IOException
initback to summary
pack-priv static native void init() throws Exception
Annotations
@SuppressFBWarnings:THROWS_METHOD_THROWS_CLAUSE_BASIC_EXCEPTION
initFDback to summary
pack-priv static native void initFD(FileDescriptor fdesc, int fd) throws IOException
initPipeback to summary
pack-priv static native boolean initPipe(FileDescriptor source, FileDescriptor sink, boolean selectable) throws IOException
initPreback to summary
pack-priv static void initPre()
initRedirectback to summary
pack-priv static native ProcessBuilder.Redirect initRedirect(FileDescriptor fd)
initServerImplback to summary
pack-priv static native void initServerImpl(ServerSocket serverSocket, AFSocketImpl<?> impl) throws IOException
isLoadedback to summary
pack-priv static boolean isLoaded()
listenback to summary
pack-priv static native void listen(FileDescriptor fd, int backlog) throws IOException
maxAddressLengthback to summary
pack-priv static native int maxAddressLength()
noopback to summary
pack-priv static native void noop()

Can be used to check (without side-effects) if the library has been loaded. Terminates normally if so; throws UnsatisfiedLinkError if not.

peerCredentialsback to summary
pack-priv static native AFUNIXSocketCredentials peerCredentials(FileDescriptor fd, AFUNIXSocketCredentials creds) throws IOException
pollback to summary
pack-priv static native int poll(AFSelector.PollFd pollFd, int timeout) throws IOException
primaryTypeback to summary
pack-priv static native Class<?> primaryType(FileDescriptor fd) throws IOException
readback to summary
pack-priv static native int read(FileDescriptor fd, byte[] buf, int off, int len, int options, AncillaryDataSupport ancillaryDataSupport, int timeoutMillis) throws IOException

Reads data from an AFSocketImpl.

Parameters
fd:FileDescriptor

The corresponding file descriptor.

buf:byte[]

The buffer to read into, or null if a single byte should be read.

off:int

The buffer offset.

len:int

The maximum number of bytes to read. Must be 1 if buf is null.

options:int

Options.

ancillaryDataSupport:AncillaryDataSupport

The ancillary data support instance, or null.

Returns:int

The number of bytes read, -1 if nothing could be read, or the byte itself iff buf was null.

Exceptions
IOException:
upon error.
receiveback to summary
pack-priv static native int receive(FileDescriptor fd, ByteBuffer directBuffer, int offset, int length, ByteBuffer directSocketAddressOut, int options, AncillaryDataSupport ancillaryDataSupport, int timeoutMillis) throws IOException
retrieveInitErrorback to summary
pack-priv static Throwable retrieveInitError()
sendback to summary
pack-priv static native int send(FileDescriptor fd, ByteBuffer directBuffer, int offset, int length, ByteBuffer directSocketAddress, int addrLen, int options, AncillaryDataSupport ancillaryDataSupport) throws IOException
setLoadedback to summary
pack-priv static void setLoaded(boolean successful)
setPortback to summary
pack-priv static native void setPort(SocketAddress addr, int port)
setPort1back to summary
pack-priv static void setPort1(SocketAddress addr, int port) throws SocketException
Annotations
@SuppressFBWarnings:THROWS_METHOD_THROWS_RUNTIMEEXCEPTION
setSocketOptionback to summary
pack-priv static native void setSocketOption(FileDescriptor fd, int level, int optionName, Object value) throws IOException
setSocketOptionIntback to summary
pack-priv static native void setSocketOptionInt(FileDescriptor fd, int optionId, int value) throws IOException
shutdownback to summary
pack-priv static native void shutdown(FileDescriptor fd, int mode) throws IOException
sockAddrLengthback to summary
pack-priv static native int sockAddrLength(int domain)
sockAddrNativeDataOffsetback to summary
pack-priv static native int sockAddrNativeDataOffset()
sockAddrNativeFamilyOffsetback to summary
pack-priv static native int sockAddrNativeFamilyOffset()
sockAddrToBytesback to summary
pack-priv static native byte[] sockAddrToBytes(int domain, ByteBuffer sockAddrDirect)
socketPairback to summary
pack-priv static native void socketPair(int domain, int type, FileDescriptor fd, FileDescriptor fd2)
socketStatusback to summary
pack-priv static native int socketStatus(FileDescriptor fd) throws IOException
socknameback to summary
pack-priv static native byte[] sockname(int domain, FileDescriptor fd, boolean peer)
sockTypeToNativeback to summary
pack-priv static native int sockTypeToNative(int type) throws IOException
systemResolveCtlIdback to summary
pack-priv static native int systemResolveCtlId(FileDescriptor fd, String ctlName) throws IOException
tipcGetLinkNameback to summary
pack-priv static native byte[] tipcGetLinkName(int peer, int bearerId) throws IOException
tipcGetNodeIdback to summary
pack-priv static native byte[] tipcGetNodeId(int peer) throws IOException
tryResolveClassback to summary
private static void tryResolveClass(String className)
unsupportedExceptionback to summary
pack-priv static UnsupportedOperationException unsupportedException()
vsockGetLocalCIDback to summary
pack-priv static native int vsockGetLocalCID() throws IOException
writeback to summary
pack-priv static native int write(FileDescriptor fd, byte[] buf, int off, int len, int options, AncillaryDataSupport ancillaryDataSupport) throws IOException

Writes data to an AFSocketImpl.

Parameters
fd:FileDescriptor

The corresponding file descriptor.

buf:byte[]

The buffer to write from, or null if a single byte should be written.

off:int

The buffer offset, or the byte to write if buf is null.

len:int

The number of bytes to write. Must be 1 if buf is null.

options:int

Options.

ancillaryDataSupport:AncillaryDataSupport

The ancillary data support instance, or null.

Returns:int

The number of bytes written (which could be 0).

Exceptions
IOException:
upon error.