mirror of
				https://github.com/traefik/traefik.git
				synced 2025-11-04 02:11:15 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			27 lines
		
	
	
		
			544 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			27 lines
		
	
	
		
			544 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package tcp
 | 
						|
 | 
						|
import (
 | 
						|
	"github.com/traefik/traefik/v2/pkg/safe"
 | 
						|
)
 | 
						|
 | 
						|
// 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 WriteCloser) {
 | 
						|
	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)
 | 
						|
}
 |