shm

package
v0.0.0-...-16d0631 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package shm provides a shared memory transport implementation.

The messages in this transport are delivered by native Go channels.

Typical usage of a connection:

cfg := NewConnection()  // Initialises a shared memory connection
s, c := cfg.Endpoints() // Equivalent to cfg.Accept(), cfg.Connect()
defer func(s *IOChan){
	if err := s.Close(); err != nil {
		// handle errors
	}(s)
}
...
defer func(c *IOChan){
	if err := c.Close(); err != nil {
		// handle errors
	}(c)
}

Client c and Server s can then be used as I/O streams implementing io.Reader and io.Writer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChannelNotReadyError

type ChannelNotReadyError struct {
	// contains filtered or unexported fields
}

ChannelNotReadyError is the kind of error where a channel is not ready to be used (e.g. uninitialised).

func (ChannelNotReadyError) Error

func (e ChannelNotReadyError) Error() string

type ConnCfg

type ConnCfg struct {
	// contains filtered or unexported fields
}

ConnCfg is a connection configuration, contains the details required to establish a connection.

func NewBufferedConnection

func NewBufferedConnection(n int) ConnCfg

NewBufferedConnection is a convenient wrapper for an in-memory connection and can be used as either server-side or client-side.

func NewConnection

func NewConnection() ConnCfg

NewConnection is a convenient wrapper for an in-memory connection and can be used as either server-side or client-side.

func (ConnCfg) Accept

func (cfg ConnCfg) Accept() transport.Channel

Accept listens for and accepts connection from a TCP socket using details from cfg, and returns the TCP stream as a ReadWriteCloser.

Accept blocks while waiting for connection to be accepted.

func (ConnCfg) Connect

func (cfg ConnCfg) Connect() transport.Channel

Connect establishes a connection with a TCP socket using details from cfg, and returns the TCP stream as a ReadWriteCloser.

func (ConnCfg) Endpoints

func (cfg ConnCfg) Endpoints() (s transport.Channel, c transport.Channel)

Endpoints is a convenient function that returns the dual endpoints created by Accept and Connect, such that messages sent to one endpoint can be received by the other and vice versa.

type IOChan

type IOChan struct {
	// contains filtered or unexported fields
}

IOChan is a connected shared memory connection, and wraps a pair of read/write Go channels for communication.

IOChan implements ReadWriteCloser and can be used as it. Messages are delimited by the data type boundary as they are passed as pointers. No serialisation are defined for IOChan.

func (*IOChan) Close

func (c *IOChan) Close() error

func (*IOChan) Recv

func (c *IOChan) Recv(ptr interface{}) error

func (*IOChan) Send

func (c *IOChan) Send(val interface{}) error

Jump to

Keyboard shortcuts

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