micro/network/tunnel/transport/listener.go

31 lines
496 B
Go
Raw Normal View History

2019-08-07 23:58:25 +03:00
package transport
import (
"go.unistack.org/micro/v3/network/transport"
"go.unistack.org/micro/v3/network/tunnel"
2019-08-07 23:58:25 +03:00
)
type tunListener struct {
l tunnel.Listener
}
func (t *tunListener) Addr() string {
2019-08-30 22:05:00 +03:00
return t.l.Channel()
2019-08-07 23:58:25 +03:00
}
func (t *tunListener) Close() error {
return t.l.Close()
}
func (t *tunListener) Accept(fn func(socket transport.Socket)) error {
for {
// accept connection
c, err := t.l.Accept()
if err != nil {
return err
}
// execute the function
go fn(c)
}
}