Documentation ¶
Overview ¶
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/...
Example:
net := pipenet.New("") h1 := net.Host("abc") h2 := net.Host("def") l, err := h1.Listen(ctx, ":10") // starts listening on address "abc:10" go func() { csrv, err := l.Accept(ctx) // 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.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsVirtNet ¶
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.
Types ¶
type Network ¶
type Network struct {
// contains filtered or unexported fields
}
Network implements synchronous in-memory TCP-like network of pipes.
func New ¶
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.