Class AFSYSTEMSocketAddress
java.lang.Object
java.net.SocketAddress
java.net.InetSocketAddress
org.newsclub.net.unix.AFSocketAddress
org.newsclub.net.unix.AFSYSTEMSocketAddress
- All Implemented Interfaces:
Serializable
An
AFSocketAddress for AF_SYSTEM sockets.- Author:
- Christian Kohlschütter
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThe AF_SYSTEM system address.Nested classes/interfaces inherited from class AFSocketAddress
AFSocketAddress.AFSocketAddressConstructor<T>Modifier and TypeClassDescriptionprotected static interfaceA reference to the constructor of an AFSocketAddress subclass. -
Method Summary
Modifier and TypeMethodDescriptionstatic AFAddressFamily<AFSYSTEMSocketAddress> Returns the correspondingAFAddressFamily.getFile()Returns theFilecorresponding with this address, if possible.intgetId()Returns the "id" part of the address.@NonNull AFSYSTEMSocketAddress.SysAddrReturns the "SysAddr" part of the address.intgetUnit()Returns the "unit" part of the address.booleanChecks if the address can be resolved to aFile.static booleanChecks if anInetAddresscan be unwrapped to anAFSYSTEMSocketAddress.static booleanChecks if aSocketAddresscan be unwrapped to anAFSYSTEMSocketAddress.static AFSYSTEMSocketAddressReturns anAFSYSTEMSocketAddressfor the given URI, if possible.static AFSYSTEMSocketAddressReturns anAFSYSTEMSocketAddressfor the given URI, if possible.static AFSYSTEMSocketAddressofSysAddrIdUnit(int javaPort, AFSYSTEMSocketAddress.SysAddr sysAddr, int id, int unit) Returns anAFSYSTEMSocketAddressthat refers to a given AF_SYSTEM socket address (i.e., referring to a particular socket instance instead of a service address).static AFSYSTEMSocketAddressofSysAddrIdUnit(AFSYSTEMSocketAddress.SysAddr sysAddr, int id, int unit) Returns anAFSYSTEMSocketAddressthat refers to a given AF_SYSTEM socket address (i.e., referring to a particular socket instance instead of a service address).toString()Tries to create a URI based on thisAFSocketAddress.static AFSYSTEMSocketAddressReturns anAFSYSTEMSocketAddressgiven a specialInetAddresshostname that encodes the byte sequence of an AF_SYSTEM socket address, like those returned byAFSocketAddress.wrapAddress().static AFSYSTEMSocketAddressunwrap(InetAddress address, int port) Returns anAFSYSTEMSocketAddressgiven a specialInetAddressthat encodes the byte sequence of an AF_SYSTEM socket address, like those returned byAFSocketAddress.wrapAddress().static AFSYSTEMSocketAddressunwrap(SocketAddress address) Returns anAFSYSTEMSocketAddressgiven a genericSocketAddress.Methods inherited from class AFSocketAddress
canMap, canMap, covers, getAddressFamily, getBytes, getInetAddress, getInetAddress, getInetAddress, getSocketAddress, isSupportedAddress, isUseDeserializationForInit, mapOrFail, mapOrFail, newBoundServerSocket, newConnectedSocket, newDeserializedAFSocketAddress, newForceBoundServerSocket, parseUnsignedInt, resolveAddress, toSocatAddressString, unwrap, unwrap, wrapAddress, writeNativeAddressToModifier and TypeMethodDescriptionstatic booleancanMap(SocketAddress addr) Checks if the givenSocketAddresscan be mapped to anAFSocketAddress.static booleancanMap(SocketAddress addr, Class<? extends AFSocketAddress> targetAddressClass) Checks if the givenSocketAddresscan be mapped to a specificAFSocketAddresssubclass.booleancovers(AFSocketAddress other) Checks if the given address could cover another address.final AFAddressFamily<?> Returns the correspondingAFAddressFamily.protected final byte[]getBytes()Returns the (non-native) byte-level representation of this address.protected final InetAddressWraps this address as anInetAddress.protected static final InetAddressgetInetAddress(FileDescriptor fdesc, boolean peerName, AFAddressFamily<?> af) Wraps the socket name/peer name of a file descriptor as anInetAddress.protected final InetAddressgetInetAddress(AFAddressFamily<?> af) Wraps an address as anInetAddress.protected static final <A extends AFSocketAddress>
@Nullable AgetSocketAddress(FileDescriptor fdesc, boolean requestPeerName, int port, AFAddressFamily<A> af) Gets the socket name/peer name of a file descriptor as anAFSocketAddress.protected static final booleanisSupportedAddress(InetAddress addr, AFAddressFamily<?> af) Checks if the given address is supported by this address family.protected static booleanChecks ifAFSocketAddressinstantiation should be performed via deserialization.static AFSocketAddressmapOrFail(SocketAddress addr) Maps the given address to anAFSocketAddress.static <A extends AFSocketAddress>
AmapOrFail(SocketAddress addr, Class<A> targetAddressClass) Maps the given address to a specificAFSocketAddresstype.Creates a new server socket bound to this address.AFSocket<?> Creates a new socket connected to this address.protected static <A extends AFSocketAddress>
AnewDeserializedAFSocketAddress(int port, byte[] socketAddress, ObjectPool.Lease<ByteBuffer> nativeAddress, AFAddressFamily<A> af, AFSocketAddress.AFSocketAddressConstructor<A> constructor) Returns a newAFSocketAddressinstance via deserialization.Creates a new server socket force-bound to this address (i.e., any additional call toServerSocket.bind(SocketAddress)will ignore the passed address and use this one instead.protected static intparseUnsignedInt(String s, int radix) Parses the string argument as an unsigned integer in the radix specified by the second argument.protected static final <A extends AFSocketAddress>
AresolveAddress(byte[] socketAddress, int port, AFAddressFamily<A> af) Resolves a junixsocket-specific byte-array representation of anAFSocketAddressto an actualAFSocketAddressinstance, possibly reusing a cached instance.@Nullable StringtoSocatAddressString(AFSocketType socketType, AFSocketProtocol socketProtocol) Returns a address string that can be used withsocat'sSOCKET-CONNECT,SOCKET-LISTEN,SOCKET-DATAGRAM, etc., address types, ornullif the address type is not natively supported by this platform.protected static final <A extends AFSocketAddress>
@NonNull Aunwrap(String hostname, int port, AFAddressFamily<A> af) Returns anAFSocketAddressgiven a specialInetAddresshostname that encodes the byte sequence of an AF_UNIX etc. socket address, like those returned byAFSocketAddress.wrapAddress().protected static final <A extends AFSocketAddress>
@NonNull Aunwrap(InetAddress address, int port, AFAddressFamily<A> af) Returns anAFSocketAddressgiven a specialInetAddressthat encodes the byte sequence of an AF_UNIX etc. socket address, like those returned byAFSocketAddress.wrapAddress().final InetAddressReturns a "special"InetAddressthat contains information about thisAFSocketAddress.final voidWrites the native (system-level) representation of this address to the given buffer.Methods inherited from class InetSocketAddress
createUnresolved, equals, getAddress, getHostName, getHostString, getPort, hashCode, isUnresolved
-
Method Details
-
ofSysAddrIdUnit
public static AFSYSTEMSocketAddress ofSysAddrIdUnit(int javaPort, AFSYSTEMSocketAddress.SysAddr sysAddr, int id, int unit) throws SocketException Returns anAFSYSTEMSocketAddressthat refers to a given AF_SYSTEM socket address (i.e., referring to a particular socket instance instead of a service address). A Java-only "IP port number" is stored along the instance for compatibility reasons.- Parameters:
javaPort- The emulated "port" number (not part of AF_SYSTEM).sysAddr- 16-bit system address (e.g., AF_SYS_KERNCONTROL)id- Controller unique identifierunit- Developer private unit number, 0 means "unspecified".- Returns:
- A corresponding
AFSYSTEMSocketAddressinstance. - Throws:
SocketException- if the operation fails.
-
ofSysAddrIdUnit
public static AFSYSTEMSocketAddress ofSysAddrIdUnit(AFSYSTEMSocketAddress.SysAddr sysAddr, int id, int unit) throws SocketException Returns anAFSYSTEMSocketAddressthat refers to a given AF_SYSTEM socket address (i.e., referring to a particular socket instance instead of a service address).- Parameters:
sysAddr- 16-bit system address (e.g., AF_SYS_KERNCONTROL)id- Controller unique identifierunit- Developer private unit number- Returns:
- A corresponding
AFSYSTEMSocketAddressinstance. - Throws:
SocketException- if the operation fails.
-
unwrap
Returns anAFSYSTEMSocketAddressgiven a specialInetAddressthat encodes the byte sequence of an AF_SYSTEM socket address, like those returned byAFSocketAddress.wrapAddress().- Parameters:
address- The "special"InetAddress.port- The port (use 0 for "none").- Returns:
- The
AFSYSTEMSocketAddressinstance. - Throws:
SocketException- if the operation fails, for example when an unsupported address is specified.
-
unwrap
Returns anAFSYSTEMSocketAddressgiven a specialInetAddresshostname that encodes the byte sequence of an AF_SYSTEM socket address, like those returned byAFSocketAddress.wrapAddress().- Parameters:
hostname- The "special" hostname, as provided byInetAddress.getHostName().port- The port (use 0 for "none").- Returns:
- The
AFSYSTEMSocketAddressinstance. - Throws:
SocketException- if the operation fails, for example when an unsupported address is specified.
-
unwrap
Returns anAFSYSTEMSocketAddressgiven a genericSocketAddress.- Parameters:
address- The address to unwrap.- Returns:
- The
AFSYSTEMSocketAddressinstance. - Throws:
SocketException- if the operation fails, for example when an unsupported address is specified.
-
toString
- Overrides:
toStringin classInetSocketAddress
-
getSysAddr
Returns the "SysAddr" part of the address.- Returns:
- The SysAddr part.
-
getId
public int getId()Returns the "id" part of the address.- Returns:
- The id part.
-
getUnit
public int getUnit()Returns the "unit" part of the address.- Returns:
- The unit part.
-
hasFilename
public boolean hasFilename()Description copied from class:AFSocketAddressChecks if the address can be resolved to aFile.- Specified by:
hasFilenamein classAFSocketAddress- Returns:
trueif the address has a filename.
-
getFile
Description copied from class:AFSocketAddressReturns theFilecorresponding with this address, if possible. AFileNotFoundExceptionis thrown if there is no filename associated with the address, which applies to addresses in the abstract namespace, for example.- Specified by:
getFilein classAFSocketAddress- Returns:
- The filename.
- Throws:
FileNotFoundException- if the address is not associated with a filename.
-
isSupportedAddress
Checks if anInetAddresscan be unwrapped to anAFSYSTEMSocketAddress.- Parameters:
addr- The instance to check.- Returns:
trueif so.- See Also:
-
isSupportedAddress
Checks if aSocketAddresscan be unwrapped to anAFSYSTEMSocketAddress.- Parameters:
addr- The instance to check.- Returns:
trueif so.- See Also:
-
addressFamily
Returns the correspondingAFAddressFamily.- Returns:
- The address family instance.
-
of
Returns anAFSYSTEMSocketAddressfor the given URI, if possible.- Parameters:
uri- The URI.- Returns:
- The address.
- Throws:
SocketException- if the operation fails.
-
of
Returns anAFSYSTEMSocketAddressfor the given URI, if possible.- Parameters:
uri- The URI.overridePort- The port to forcibly use, or-1for "don't override".- Returns:
- The address.
- Throws:
SocketException- if the operation fails.
-
toURI
Description copied from class:AFSocketAddressTries to create a URI based on thisAFSocketAddress.- Overrides:
toURIin classAFSocketAddress- Parameters:
scheme- The target scheme.template- An optional template to reuse certain parameters (e.g., the "path" component for anhttprequest), ornull.- Returns:
- The URI.
- Throws:
IOException- on error.
-