Documentation ¶
Overview ¶
The netchan package implements type-safe networked channels: it allows the two ends of a channel to appear on different computers connected by a network. It does this by transporting data sent to a channel on one machine so it can be recovered by a receive of a channel of the same type on the other.
An exporter publishes a set of channels by name. An importer connects to the exporting machine and imports the channels by name. After importing the channels, the two machines can use the channels in the usual way.
Networked channels are not synchronized; they always behave as if there is a buffer of at least one element between the two machines.
TODO: at the moment, the exporting machine must send and the importing machine must receive. This restriction will be lifted soon.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Exporter ¶
type Exporter struct {
// contains filtered or unexported fields
}
An Exporter allows a set of channels to be published on a single network port. A single machine may have multiple Exporters but they must use different ports.
func NewExporter ¶
NewExporter creates a new Exporter to export channels on the network and local address defined as in net.Listen.
func (*Exporter) Export ¶
Export exports a channel of a given type and specified direction. The channel to be exported is provided in the call and may be of arbitrary channel type. Despite the literal signature, the effective signature is
Export(name string, chT chan T, dir Dir)
where T must be a struct, pointer to struct, etc.
type Importer ¶
type Importer struct {
// contains filtered or unexported fields
}
An Importer allows a set of channels to be imported from a single remote machine/network port. A machine may have multiple importers, even from the same machine/network port.
func NewImporter ¶
NewImporter creates a new Importer object to import channels from an Exporter at the network and remote address as defined in net.Dial. The Exporter must be available and serving when the Importer is created.
func (*Importer) Import ¶
Import imports a channel of the given type and specified direction. It is equivalent to ImportNValues with a count of 0, meaning unbounded.
func (*Importer) ImportNValues ¶
func (imp *Importer) ImportNValues(name string, chT interface{}, dir Dir, pT interface{}, n int) os.Error
ImportNValues imports a channel of the given type and specified direction and then receives or transmits up to n values on that channel. A value of n==0 implies an unbounded number of values. The channel to be bound to the remote site's channel is provided in the call and may be of arbitrary channel type. Despite the literal signature, the effective signature is
ImportNValues(name string, chT chan T, dir Dir, pT T)
where T must be a struct, pointer to struct, etc. pT may be more indirect than the value type of the channel (e.g. chan T, pT *T) but it must be a pointer. Example usage:
imp, err := NewImporter("tcp", "netchanserver.mydomain.com:1234") if err != nil { log.Exit(err) } ch := make(chan myType) err := imp.ImportNValues("name", ch, Recv, new(myType), 1) if err != nil { log.Exit(err) } fmt.Printf("%+v\n", <-ch)
(TODO: Can we eliminate the need for pT?)