2019-03-14 08:30:04 +00:00
|
|
|
package tcp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
|
2019-03-15 08:42:03 +00:00
|
|
|
"github.com/containous/traefik/pkg/safe"
|
2019-03-14 08:30:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// HandlerSwitcher is a TCP handler switcher
|
|
|
|
type HandlerSwitcher struct {
|
|
|
|
router safe.Safe
|
|
|
|
}
|
|
|
|
|
|
|
|
// ServeTCP forwards the TCP connection to the current active handler
|
|
|
|
func (s *HandlerSwitcher) ServeTCP(conn net.Conn) {
|
|
|
|
handler := s.router.Get()
|
|
|
|
h, ok := handler.(Handler)
|
|
|
|
if ok {
|
|
|
|
h.ServeTCP(conn)
|
|
|
|
} else {
|
|
|
|
conn.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Switch sets the new TCP handler to use for new connections
|
|
|
|
func (s *HandlerSwitcher) Switch(handler Handler) {
|
|
|
|
s.router.Set(handler)
|
|
|
|
}
|