ipc

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package ipc provides a basic, dumb implementation of discrete messaging over various underlying transport protocols. Supported protocols are three kinds of Unix domain sockets (streaming, sequential packet, datagram) and local UDP sockets. For stream sockets, messages are prefixed with a 4 byte size so that the connection knows how many bytes to pull off for each message, preserving message boundaries.

The Conn interface represents a connection between two endpoints, and is returned by all functions that create clients; the Server interface represents a running server that spawns new Conns as clients connect to it. As a Server receives new connections, it will push new clients onto the channel accessible by Server.NewConns(). Allowing message routing between named clients is left to the higher-level multi package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSocketPath

func GetSocketPath(socketName string) string

GetSocketPath returns a platform-appropriate path for the given socket name

Types

type Conn

type Conn interface {
	// Read a message - returns an empty slice if nothing is available, nil if
	// the connection has been shut down
	Read() []byte

	// Read a message and block until one becomes available (returns the buffer)
	// or the connection is closed (returns nil)
	ReadBlock() []byte

	// Write the given buffer to the other end
	Write([]byte) (int, error)

	// Close the connection and associated resources
	Close() error
}

Conn represents a connection between two specific network endpoints - a client will hold one Conn to the server it's connected to, a server will hold individual Conns for each client that's connected to it.

func NewFileConn

func NewFileConn(fd uintptr) (Conn, error)

NewFileConn returns a connection that will operate on the given file descriptor

func NewUDPClient

func NewUDPClient(ip string, port int) (Conn, error)

NewUDPClient returns a new Socket that will attempt to connect to the server on the given IP and port

func NewUnixClient

func NewUnixClient(path string) (Conn, error)

NewUnixClient returns a new connection to the server at the specified path, assuming there are no errors when connecting

func NewUnixPacketClient

func NewUnixPacketClient(path string) (Conn, error)

NewUnixPacketClient returns a new server object listening for clients on the specified path, if no errors are encountered

func NewUnixgramClient

func NewUnixgramClient(path string, name string) (Conn, error)

NewUnixgramClient returns a new connection to the server at the specified path, assuming there are no errors when connecting

type Server

type Server interface {
	NewConns() <-chan Conn
	Close() error
}

Server represents a running server waiting for connections. Client connections can be accessed by pulling new clients off the channel returned by NewConns().

func NewUDPServer

func NewUDPServer(port int) (Server, error)

NewUDPServer returns a new Server that will listen for clients on the given local port

func NewUnixPacketServer

func NewUnixPacketServer(path string) (Server, error)

NewUnixPacketServer returns a new connection to the server at the specified path, assuming there are no errors when connecting

func NewUnixServer

func NewUnixServer(path string) (Server, error)

NewUnixServer returns a new server object listening for clients on the specified path, if no errors are encountered

func NewUnixgramServer

func NewUnixgramServer(path string) (Server, error)

NewUnixgramServer returns a new server object listening for clients on the specified path, if no errors are encountered

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL