package hvsock

  1. Overview
  2. Docs

Low-level interface to the AF_VSOCK socket family available on Linux kernels.

type port = int32

Ports are similar to TCP and UDP ports.

type cid =
  1. | Any

    Any address for binding

  2. | Hypervisor

    Reserved for services built into the hypervisor

  3. | Host

    Well-known address of the host

  4. | Id of int32

    A specific VM id


A Context Identifier (CID) identifies the source or destination of a connection

val string_of_cid : cid -> string
val local : unit -> cid

local () returns the CID of the local VM

type sockaddr = {
  1. cid : cid;
  2. port : port;

An AF_VSOCK socket address

include Af_common.S with type sockaddr := sockaddr and type t = Unix.file_descr
type t = Unix.file_descr
val string_of_sockaddr : sockaddr -> string
val create : unit -> t

create () creates an unbound socket

val bind : t -> sockaddr -> unit

bind socket sockaddr binds socket to sockaddr

val listen : t -> int -> unit

listen socket queue_length sets the socket to listening mode with the given maximum queue length

val accept : t -> t * sockaddr

accept fd accepts a single connection

val connect : ?timeout_ms:int -> t -> sockaddr -> unit

connect ?timeout_ms fd sockaddr connects to a remote socket. On Windows the raw connect call can block forever if the server is not running when the call is executed (even if the server starts up afterwards) there is a default timeout of 300ms. On timeout this will raise Unix_error(Unix.ETIMEDOUT)

val writev : t -> Cstruct.t list -> int

Write a list of buffers

val read_into : t -> Cstruct.t -> int

Read into a buffer, returning the number of bytes written

val shutdown_read : t -> unit

Close the read half of the connection

val shutdown_write : t -> unit

Close the write half of the connection

val close : t -> unit

Close both halves of the connection


Innovation. Community. Security.