go123: lab.nexedi.com/kirr/go123/xnet/pipenet Index | Files

package pipenet

import "lab.nexedi.com/kirr/go123/xnet/pipenet"

Package pipenet provides TCP-like synchronous in-memory network of net.Pipes.

Addresses on pipenet are host:port pairs. A host is xnet.Networker and so can be worked with similarly to regular TCP network with Dial/Listen/Accept/...


net := pipenet.New("")
h1 := net.Host("abc")
h2 := net.Host("def")

l, err := h1.Listen(":10")          // starts listening on address "abc:10"
go func() {
	csrv, err := l.Accept()     // csrv will have LocalAddr "abc:1"
ccli, err := h2.Dial(ctx, "abc:10") // ccli will be connection between "def:1" - "abc:1"

Pipenet might be handy for testing interaction of networked applications in 1 process without going to OS networking stack.

See also package lab.nexedi.com/kirr/go123/xnet/lonet for similar network that can work across several OS-level processes.


Package Files


func AsVirtNet Uses

func AsVirtNet(n *Network) *virtnet.SubNetwork

AsVirtNet exposes Network as virtnet subnetwork.

Since pipenet works entirely in RAM and in 1 OS process, its user interface is simpler compared to more general virtnet - for example there is no error when creating hosts. However sometimes it is handy to get access to pipenet network via full virtnet interface, when the code that is using pipenet network does not want to depend on pipenet API specifics.

type Network Uses

type Network struct {
    // contains filtered or unexported fields

Network implements synchronous in-memory TCP-like network of pipes.

func New Uses

func New(name string) *Network

New creates new pipenet Network.

Name is name of this network under "pipe" namespace, e.g. "╬▒" will give full network name "pipe╬▒".

New does not check whether network name provided is unique.

func (*Network) Host Uses

func (n *Network) Host(name string) *virtnet.Host

Host returns network access point by name.

If there was no such host before it creates new one.

Host panics if underlying virtnet subnetwork was shut down.

func (*Network) Network Uses

func (n *Network) Network() string

Network returns name of the network.

Package pipenet imports 6 packages (graph). Updated 2020-06-18. Refresh now. Tools for package owners.