github.com/slackhq/nebula@v1.9.0/service/listener.go (about)

     1  package service
     2  
     3  import (
     4  	"io"
     5  	"net"
     6  )
     7  
     8  type tcpListener struct {
     9  	port   uint16
    10  	s      *Service
    11  	addr   *net.TCPAddr
    12  	accept chan net.Conn
    13  }
    14  
    15  func (l *tcpListener) Accept() (net.Conn, error) {
    16  	conn, ok := <-l.accept
    17  	if !ok {
    18  		return nil, io.EOF
    19  	}
    20  	return conn, nil
    21  }
    22  
    23  func (l *tcpListener) Close() error {
    24  	l.s.mu.Lock()
    25  	defer l.s.mu.Unlock()
    26  	delete(l.s.mu.listeners, uint16(l.addr.Port))
    27  
    28  	close(l.accept)
    29  
    30  	return nil
    31  }
    32  
    33  // Addr returns the listener's network address.
    34  func (l *tcpListener) Addr() net.Addr {
    35  	return l.addr
    36  }