Commit 04b2b074 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent b1e8b102
...@@ -101,6 +101,11 @@ func (e *entry) empty() bool { ...@@ -101,6 +101,11 @@ func (e *entry) empty() bool {
return e.pipev[0] == nil && e.pipev[1] == nil && e.listener == nil return e.pipev[0] == nil && e.pipev[1] == nil && e.listener == nil
} }
// addr returns address corresponding to entry
func (e *entry) addr() *Addr {
return &Addr{network: e.network.netname(), addr: fmt.Sprintf("%d", e.port)}
}
func (a *Addr) Network() string { return a.network } func (a *Addr) Network() string { return a.network }
func (a *Addr) String() string { return a.addr } // XXX Network() + ":" + a.addr ? func (a *Addr) String() string { return a.addr } // XXX Network() + ":" + a.addr ?
func (n *Network) netname() string { return NetPrefix + n.Name } func (n *Network) netname() string { return NetPrefix + n.Name }
...@@ -231,15 +236,12 @@ func (n *Network) Dial(addr string) (net.Conn, error) { ...@@ -231,15 +236,12 @@ func (n *Network) Dial(addr string) (net.Conn, error) {
// Addr returns address where listener is accepting incoming connections // Addr returns address where listener is accepting incoming connections
func (l *listener) Addr() net.Addr { func (l *listener) Addr() net.Addr {
e := l.entry // NOTE no +"l" suffix e.g. because Dial(l.Addr()) must work
n := e.network return l.entry.addr()
return &Addr{network: n.netname(), addr: fmt.Sprintf("%d", e.port)} // NOTE no c/s XXX -> +l ?
} }
// XXX conn.Close - unregister from network.connv // Close closes pipe endpoint and unregisters conn from Network
// XXX conn.LocalAddr -> ... // All currently in-flight blocking IO is interuppted with an error
// XXX conn.RemoteAddr -> ...
func (c *conn) Close() (err error) { func (c *conn) Close() (err error) {
c.closeOnce.Do(func() { c.closeOnce.Do(func() {
err = c.Conn.Close() err = c.Conn.Close()
...@@ -260,6 +262,23 @@ func (c *conn) Close() (err error) { ...@@ -260,6 +262,23 @@ func (c *conn) Close() (err error) {
return err return err
} }
// LocalAddr returns address of local end of connection
// it is entry address + "c" (client) or "s" (server) suffix depending on
// whether pipe endpoint was created via Dial or Accept.
func (c *conn) LocalAddr() net.Addr {
addr := c.entry.addr()
addr.addr += string("cs"[c.endpoint])
return addr
}
// RemoteAddr returns address of remote end of connection
// it is entry address + "c" or "s" suffix -- see LocalAddr for details
func (c *conn) RemoteAddr() net.Addr {
addr := c.entry.addr()
addr.addr += string("sc"[c.endpoint])
return addr
}
......
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