2019-08-07 23:58:25 +03:00
|
|
|
package transport
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/micro/go-micro/transport"
|
|
|
|
"github.com/micro/go-micro/tunnel"
|
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|