- All Implemented Interfaces:
Closeable
,AutoCloseable
,AFSocketExtensions
,AFSomeSocket
,AFSomeSocketThing
,FileDescriptorAccess
,AFVSOCKSocketExtensions
public final class AFVSOCKSocket
extends AFSocket<AFVSOCKSocketAddress>
implements AFVSOCKSocketExtensions
Implementation of an
AF_VSOCK
socket.- Author:
- Christian Kohlschütter
-
Nested Class Summary
Nested classes/interfaces inherited from class org.newsclub.net.unix.AFSocket
AFSocket.Constructor<A extends AFSocketAddress>
-
Method Summary
Modifier and TypeMethodDescriptionstatic AFVSOCKSocket
Creates a newAFSocket
and connects it to the givenAFVSOCKSocketAddress
.static int
Returns the local CID.static boolean
Returnstrue
iffAFVSOCKSocket
s (sockets of type "AF_VSOCK") are supported by the current Java VM and the kernel.static void
Very basic self-test function.protected AFVSOCKSocketChannel
Creates a newAFSocketChannel
for this socket.static AFVSOCKSocket
Creates a new, unboundAFSocket
.static AFVSOCKSocket
Creates a new, unbound, "strict"AFSocket
.Methods inherited from class org.newsclub.net.unix.AFSocket
addCloseable, bind, checkConnectionClosed, close, connect, connect, connectHook, connectTo, connectTo, ensureAncillaryReceiveBufferSize, ensureSupported, ensureUnsafeSupported, forceConnectAddress, getAncillaryReceiveBufferSize, getFileDescriptor, getImplExtensions, getInputStream, getLoadedLibrary, getLocalSocketAddress, getOutputStream, getRemoteSocketAddress, getVersion, isBound, isClosed, isConnected, isRunningOnAndroid, newInstance, removeCloseable, setAncillaryReceiveBufferSize, setShutdownOnClose, socketAddressClass, supports, supports, toString
Methods inherited from class java.net.Socket
getInetAddress, getKeepAlive, getLocalAddress, getLocalPort, getOOBInline, getOption, getPort, getReceiveBufferSize, getReuseAddress, getSendBufferSize, getSoLinger, getSoTimeout, getTcpNoDelay, getTrafficClass, isInputShutdown, isOutputShutdown, sendUrgentData, setKeepAlive, setOOBInline, setOption, setPerformancePreferences, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setSocketImplFactory, setSoLinger, setSoTimeout, setTcpNoDelay, setTrafficClass, shutdownInput, shutdownOutput, supportedOptions
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.newsclub.net.unix.AFSocketExtensions
ensureAncillaryReceiveBufferSize, getAncillaryReceiveBufferSize, setAncillaryReceiveBufferSize
-
Method Details
-
isSupported
public static boolean isSupported()Returnstrue
iffAFVSOCKSocket
s (sockets of type "AF_VSOCK") are supported by the current Java VM and the kernel. To supportAFVSOCKSocket
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 checkingAFSocket.isSupported()
andAFSocket.supports(AFSocketCapability)
withAFSocketCapability.CAPABILITY_VSOCK
.- Returns:
true
iff supported.
-
newChannel
Description copied from class:AFSocket
Creates a newAFSocketChannel
for this socket.- Specified by:
newChannel
in classAFSocket<AFVSOCKSocketAddress>
- Returns:
- The new instance.
-
newInstance
Creates a new, unboundAFSocket
. This "default" implementation is a bit "lenient" with respect to the specification. In particular, we ignore calls toSocket.getTcpNoDelay()
andSocket.setTcpNoDelay(boolean)
.- Returns:
- A new, unbound socket.
- Throws:
IOException
- if the operation fails.
-
newStrictInstance
Creates a new, unbound, "strict"AFSocket
. This call uses an implementation that tries to be closer to the specification thannewInstance()
, at least for some cases.- Returns:
- A new, unbound socket.
- Throws:
IOException
- if the operation fails.
-
connectTo
Creates a newAFSocket
and connects it to the givenAFVSOCKSocketAddress
.- Parameters:
addr
- The address to connect to.- Returns:
- A new, connected socket.
- Throws:
IOException
- if the operation fails.
-
getChannel
- Overrides:
getChannel
in classAFSocket<AFVSOCKSocketAddress>
-
getLocalCID
Returns the local CID. If the system does not support vsock, or status about support cannot be retrieved, -1 (AFVSOCKSocketAddress.VMADDR_CID_ANY
) is returned. The value may be cached upon initialization of the library.- Returns:
- The CID, or -1.
- Throws:
IOException
- on error.
-
main
Very basic self-test function. Prints "supported" and "capabilities" status to System.out.- Parameters:
args
- ignored.
-