Documentation
¶
Overview ¶
Package vsock provides access to Linux VM sockets (AF_VSOCK) for communication between a hypervisor and its virtual machines.
The types in this package implement interfaces provided by package net and may be used in applications that expect a net.Listener or net.Conn.
- *Addr implements net.Addr
- *Conn implements net.Conn
- *Listener implements net.Listener
Index ¶
- Constants
- func ContextID() (uint32, error)
- type Addr
- type Config
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) CloseRead() error
- func (c *Conn) CloseWrite() error
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) Read(b []byte) (int, error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) SetDeadline(t time.Time) error
- func (c *Conn) SetReadDeadline(t time.Time) error
- func (c *Conn) SetWriteDeadline(t time.Time) error
- func (c *Conn) SyscallConn() (syscall.RawConn, error)
- func (c *Conn) Write(b []byte) (int, error)
- type Listener
Constants ¶
const ( // Hypervisor specifies that a socket should communicate with the hypervisor // process. Note that this is _not_ the same as a socket owned by a process // running on the hypervisor. Most users should probably use Host instead. Hypervisor = 0x0 // Local specifies that a socket should communicate with a matching socket // on the same machine. This provides an alternative to UNIX sockets or // similar and may be useful in testing VM sockets applications. Local = 0x1 // Host specifies that a socket should communicate with processes other than // the hypervisor on the host machine. This is the correct choice to // communicate with a process running on a hypervisor using a socket dialed // from a guest. Host = 0x2 )
Variables ¶
This section is empty.
Functions ¶
func ContextID ¶
ContextID retrieves the local VM sockets context ID for this system. ContextID can be used to directly determine if a system is capable of using VM sockets.
If the kernel module is unavailable, access to the kernel module is denied, or VM sockets are unsupported on this system, it returns an error.
Types ¶
type Addr ¶
type Addr struct {
ContextID, Port uint32
}
An Addr is the address of a VM sockets endpoint.
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
A Conn is a VM sockets implementation of a net.Conn.
func Dial ¶
Dial dials a connection-oriented net.Conn to a VM sockets listener. The context ID and port parameters specify the address of the listener. Config specifies optional configuration for the Conn. If config is nil, a default configuration will be used.
If dialing a connection from the hypervisor to a virtual machine, the VM's context ID should be specified.
If dialing from a VM to the hypervisor, Hypervisor should be used to communicate with the hypervisor process, or Host should be used to communicate with other processes on the host machine.
When the connection is no longer needed, Close must be called to free resources.
func DialContext ¶
DialContext connects to the address on the named network using the provided context.
The provided Context must be non-nil. If the context expires before the connection is complete, an error is returned. Once successfully connected, any expiration of the context will not affect the connection.
See func Dial for a description of the contextID and port parameters.
func (*Conn) CloseRead ¶
CloseRead shuts down the reading side of the VM sockets connection. Most callers should just use Close.
func (*Conn) CloseWrite ¶
CloseWrite shuts down the writing side of the VM sockets connection. Most callers should just use Close.
func (*Conn) LocalAddr ¶
LocalAddr returns the local network address. The Addr returned is shared by all invocations of LocalAddr, so do not modify it.
func (*Conn) RemoteAddr ¶
RemoteAddr returns the remote network address. The Addr returned is shared by all invocations of RemoteAddr, so do not modify it.
func (*Conn) SetDeadline ¶
SetDeadline implements the net.Conn SetDeadline method.
func (*Conn) SetReadDeadline ¶
SetReadDeadline implements the net.Conn SetReadDeadline method.
func (*Conn) SetWriteDeadline ¶
SetWriteDeadline implements the net.Conn SetWriteDeadline method.
func (*Conn) SyscallConn ¶
SyscallConn returns a raw network connection. This implements the syscall.Conn interface.
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
A Listener is a VM sockets implementation of a net.Listener.
func FileListener ¶
FileListener returns a copy of the network listener corresponding to an open os.File. It is the caller's responsibility to close the Listener when finished. Closing the Listener does not affect the os.File, and closing the os.File does not affect the Listener.
This function is intended for advanced use cases and most callers should use Listen instead.
func Listen ¶
Listen opens a connection-oriented net.Listener for incoming VM sockets connections. The port parameter specifies the port for the Listener. Config specifies optional configuration for the Listener. If config is nil, a default configuration will be used.
To allow the server to assign a port automatically, specify 0 for port. The address of the server can be retrieved using the Addr method.
Listen automatically infers the appropriate context ID for this machine by calling ContextID and passing that value to ListenContextID. Callers with advanced use cases (such as using the Local context ID) may wish to use ListenContextID directly.
When the Listener is no longer needed, Close must be called to free resources.
func ListenContextID ¶
ListenContextID is the same as Listen, but also accepts an explicit context ID parameter. This function is intended for advanced use cases and most callers should use Listen instead.
See the documentation of Listen for more details.
func (*Listener) Accept ¶
Accept implements the Accept method in the net.Listener interface; it waits for the next call and returns a generic net.Conn. The returned net.Conn will always be of type *Conn.
func (*Listener) Addr ¶
Addr returns the listener's network address, a *Addr. The Addr returned is shared by all invocations of Addr, so do not modify it.
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
vscp
Command vscp provides a scp-like utility for copying files over VM sockets.
|
Command vscp provides a scp-like utility for copying files over VM sockets. |
internal
|
|
vsutil
Package vsutil provides added functionality for package vsock-internal use.
|
Package vsutil provides added functionality for package vsock-internal use. |