Standard library
Unix sockets
Unix domain sockets.
Introduction
Unix domain sockets. Import std/net/unix to bind the module as unix. Call free functions as unix.name(...). Struct methods use a receiver value.
/ std/net/unix
This page is the package reference for std/net/unix. Private helpers used only by co-located tests are not listed.
Struct · listener
Unix domain listener shape. The shape is exported as unix.listener. Methods on the receiver are listed next.
/ std/net/unix
; shape: unix.listener
$ listener = unix.listen(p'/tmp/echo.sock')
Parameters: No parameters. Type or shape export. Returns: Shape export used for literals and methods.
listener · accept
Accepts the next Unix domain connection. Failure may return a conn with handle 0 and open false. Call form: listener.accept().
/ std/net/unix
$ conn = listener.accept()
Parameters: No parameters. Returns: conn product for the accepted peer.
listener · close
Closes the Unix domain listener. Call form: listener.close().
/ std/net/unix
listener.close()
Parameters: No parameters. Returns: The listener receiver.
Struct · conn
Unix domain connection shape. The shape is exported as unix.conn. Methods on the receiver are listed next.
/ std/net/unix
; shape: unix.conn
$ conn = unix.connect(p'/tmp/echo.sock')
Parameters: No parameters. Type or shape export. Returns: Shape export used for literals and methods.
conn · read
Reads up to limit bytes from the Unix domain connection. Call form: conn.read(limit).
/ std/net/unix
$ data = conn.read(4096)
Parameters: limit: maximum bytes to read. Returns: Bytes read.
conn · write
Writes data to the Unix domain connection. Call form: conn.write(data).
/ std/net/unix
$ n = conn.write("hi")Parameters: data: bytes or string to send. Returns: Integer bytes written, or failure status.
conn · close
Closes the connection and marks it closed. Call form: conn.close().
/ std/net/unix
conn.close()
Parameters: No parameters. Returns: The connection receiver.
Functions
Free functions on unix. Each function has a short description, an example, then parameters and return shape.
listen
Binds a Unix domain listener on path. Call form: unix.listen(path).
/ std/net/unix
$ listener = unix.listen(p'/tmp/echo.sock')
Parameters: path: socket path. Returns: Unix listener product.
accept
Accepts the next Unix domain connection. Call form: unix.accept(lis).
/ std/net/unix
$ conn = unix.accept(listener)
Parameters: listener: Unix listener. Returns: Unix connection product.
connect
Connects to a Unix domain socket path. Call form: unix.connect(path).
/ std/net/unix
$ conn = unix.connect(p'/tmp/echo.sock')
Parameters: path: socket path. Returns: Unix connection product.
read
Reads bytes from a Unix domain connection. Call form: unix.read(c, limit).
/ std/net/unix
$ data = unix.read(conn, 4096)
Parameters: conn: Unix connection. limit: maximum bytes. Returns: Bytes read.
write
Writes bytes to a Unix domain connection. Call form: unix.write(c, data).
/ std/net/unix
$ n = unix.write(conn, "hi")
Parameters: conn: Unix connection. data: bytes or string. Returns: Integer bytes written, or -1 on failure.
close
Closes a Unix domain connection or listener. Call form: unix.close(c).
/ std/net/unix
unix.close(conn)
Parameters: resource: connection or listener. Returns: None.