Commit 258372a2 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 71865607
...@@ -703,7 +703,7 @@ func Listen(net xnet.Networker, laddr string) (*Listener, error) { ...@@ -703,7 +703,7 @@ func Listen(net xnet.Networker, laddr string) (*Listener, error) {
} }
l := &Listener{ l := &Listener{
Listener: rawl, l: rawl,
acceptq: make(chan accepted), acceptq: make(chan accepted),
closed: make(chan struct{}), closed: make(chan struct{}),
} }
...@@ -712,8 +712,10 @@ func Listen(net xnet.Networker, laddr string) (*Listener, error) { ...@@ -712,8 +712,10 @@ func Listen(net xnet.Networker, laddr string) (*Listener, error) {
return l, nil return l, nil
} }
// Listener wraps net.Listener to return handshaked NodeLink on Accept.
// Create only via Listen.
type Listener struct { type Listener struct {
net.Listener l net.Listener
acceptq chan accepted acceptq chan accepted
closed chan struct {} closed chan struct {}
} }
...@@ -724,7 +726,7 @@ type accepted struct { ...@@ -724,7 +726,7 @@ type accepted struct {
} }
func (l *Listener) Close() error { func (l *Listener) Close() error {
err := l.Listener.Close() err := l.l.Close()
close(l.closed) close(l.closed)
return err return err
} }
...@@ -743,7 +745,7 @@ func (l *Listener) run() { ...@@ -743,7 +745,7 @@ func (l *Listener) run() {
} }
// XXX add backpressure on too much incoming connections without client .Accept // XXX add backpressure on too much incoming connections without client .Accept
conn, err := l.Listener.Accept() conn, err := l.l.Accept()
go l.accept(runCtx, conn, err) go l.accept(runCtx, conn, err)
} }
} }
...@@ -774,7 +776,7 @@ func (l *Listener) Accept() (*NodeLink, error) { ...@@ -774,7 +776,7 @@ func (l *Listener) Accept() (*NodeLink, error) {
select{ select{
case <-l.closed: case <-l.closed:
// we know raw listener is already closed - return proper error about it // we know raw listener is already closed - return proper error about it
_, err := l.Listener.Accept() _, err := l.l.Accept()
return nil, err return nil, err
case a := <-l.acceptq: case a := <-l.acceptq:
...@@ -782,6 +784,10 @@ func (l *Listener) Accept() (*NodeLink, error) { ...@@ -782,6 +784,10 @@ func (l *Listener) Accept() (*NodeLink, error) {
} }
} }
func (l *Listener) Addr() net.Addr {
return l.l.Addr()
}
// ---- for convenience: Conn -> NodeLink & local/remote link addresses ---- // ---- for convenience: Conn -> NodeLink & local/remote link addresses ----
// LocalAddr returns local address of the underlying link to peer. // LocalAddr returns local address of the underlying link to peer.
......
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