gitee.com/liuxuezhan/go-micro-v1.18.0@v1.0.0/tunnel/transport/listener.go (about)

     1  package transport
     2  
     3  import (
     4  	"gitee.com/liuxuezhan/go-micro-v1.18.0/transport"
     5  	"gitee.com/liuxuezhan/go-micro-v1.18.0/tunnel"
     6  )
     7  
     8  type tunListener struct {
     9  	l tunnel.Listener
    10  }
    11  
    12  func (t *tunListener) Addr() string {
    13  	return t.l.Channel()
    14  }
    15  
    16  func (t *tunListener) Close() error {
    17  	return t.l.Close()
    18  }
    19  
    20  func (t *tunListener) Accept(fn func(socket transport.Socket)) error {
    21  	for {
    22  		// accept connection
    23  		c, err := t.l.Accept()
    24  		if err != nil {
    25  			return err
    26  		}
    27  		// execute the function
    28  		go fn(c)
    29  	}
    30  }