Commit 4dd76879 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent e8176894
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
// //
// Example: // Example:
// //
// XXX adjust
// net := pipenet.New("") // net := pipenet.New("")
// h1 := net.Host("abc") // h1 := net.Host("abc")
// h2 := net.Host("def") // h2 := net.Host("def")
...@@ -60,11 +59,10 @@ var ( ...@@ -60,11 +59,10 @@ var (
type Addr struct { type Addr struct {
Net string // full network name, e.g. "pipe" Net string // full network name, e.g. "pipe"
Host string // name of host access point on the network Host string // name of host access point on the network
Port int // port on host XXX -1, if anonymous ? Port int // port on host
} }
// Network implements synchronous in-memory network of pipes // Network implements synchronous in-memory network of pipes
// XXX text about hosts & ports and routing logic
type Network struct { type Network struct {
// name of this network under "pipe" namespace -> e.g. "" // name of this network under "pipe" namespace -> e.g. ""
// full network name will be reported as "pipe"+name // full network name will be reported as "pipe"+name
...@@ -91,7 +89,7 @@ var _ xnet.Networker = (*Host)(nil) ...@@ -91,7 +89,7 @@ var _ xnet.Networker = (*Host)(nil)
// socket represents one endpoint entry on Network // socket represents one endpoint entry on Network
// it can be either already connected or listening // it can be either already connected or listening
type socket struct { type socket struct {
host *Host // host/port this socket is binded to host *Host // host/port this socket is bound to
port int port int
conn *conn // connection endpoint is here if != nil conn *conn // connection endpoint is here if != nil
...@@ -136,7 +134,7 @@ func New(name string) *Network { ...@@ -136,7 +134,7 @@ func New(name string) *Network {
} }
// Host returns network access point by name // Host returns network access point by name
// if there was no such host it creates new one // if there was no such host before it creates new one
func (n *Network) Host(name string) *Host { func (n *Network) Host(name string) *Host {
n.mu.Lock() n.mu.Lock()
defer n.mu.Unlock() defer n.mu.Unlock()
...@@ -150,7 +148,7 @@ func (n *Network) Host(name string) *Host { ...@@ -150,7 +148,7 @@ func (n *Network) Host(name string) *Host {
return host return host
} }
// resolveAddr resolved addr on the network from the host point of view // resolveAddr resolves addr on the network from the host point of view
// must be called with Network.mu held // must be called with Network.mu held
func (h *Host) resolveAddr(addr string) (host *Host, port int, err error) { func (h *Host) resolveAddr(addr string) (host *Host, port int, err error) {
hoststr, portstr, err := net.SplitHostPort(addr) hoststr, portstr, err := net.SplitHostPort(addr)
...@@ -188,7 +186,7 @@ func (h *Host) Listen(laddr string) (net.Listener, error) { ...@@ -188,7 +186,7 @@ func (h *Host) Listen(laddr string) (net.Listener, error) {
if laddr == "" { if laddr == "" {
sk = h.allocFreeSocket() sk = h.allocFreeSocket()
// else we resolve/checr address, whether it is already used and if not allocate socket in-place // else we resolve/check address, whether it is already used and if not allocate socket in-place
} else { } else {
var netladdr net.Addr var netladdr net.Addr
lerr := func(err error) error { lerr := func(err error) error {
...@@ -383,12 +381,12 @@ func (h *Host) allocFreeSocket() *socket { ...@@ -383,12 +381,12 @@ func (h *Host) allocFreeSocket() *socket {
return sk return sk
} }
// empty checks whether sockets's both pipe endpoint and listener are all nil // empty checks whether socket's both conn and listener are all nil
func (sk *socket) empty() bool { func (sk *socket) empty() bool {
return sk.conn == nil && sk.listener == nil return sk.conn == nil && sk.listener == nil
} }
// addr returns address corresponding to entry // addr returns address corresponding to socket
func (sk *socket) addr() *Addr { func (sk *socket) addr() *Addr {
h := sk.host h := sk.host
return &Addr{Net: h.Network(), Host: h.name, Port: sk.port} return &Addr{Net: h.Network(), Host: h.name, Port: sk.port}
...@@ -405,5 +403,5 @@ func (l *listener) Addr() net.Addr { ...@@ -405,5 +403,5 @@ func (l *listener) Addr() net.Addr {
// Network returns full network name of this network // Network returns full network name of this network
func (n *Network) Network() string { return NetPrefix + n.name } func (n *Network) Network() string { return NetPrefix + n.name }
// Network returns full network name of underllying network // Network returns full network name of underlying network
func (h *Host) Network() string { return h.network.Network() } func (h *Host) Network() string { return h.network.Network() }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment