// ServeTCP forwards the connection to a backend
ServeTCP forwards the connection to a backend
// ServeTCP forwards the connection to a backend
func (p *TCPProxy) ServeTCP(conn net.Conn) {
	log.Debugf("Handling tcp connection from %s", conn.RemoteAddr())
	defer conn.Close()
	relay, err := net.DialTCP("tcp", nil, p.remote)
	if err != nil {
		log.Errorf("Error while connection to backend: %v", err)
		return
	}
	defer relay.Close()
	errChan := make(chan error)
	go p.connCopy(conn, relay, errChan)
	go p.connCopy(relay, conn, errChan)
	err = <-errChan
	if err != nil {
		log.Errorf("Error during connection: %v", err)
	}
	<-errChan
}
func ( p * TCPProxy ) ServeTCP ( conn net . Conn ) { log . Debugf ( " " , conn . RemoteAddr ( ) ) defer conn . Close ( ) relay , err := net . DialTCP ( " " , nil , p . remote ) if err != nil { log . Errorf ( " " , err ) return } defer relay . Close ( ) errChan := make ( chan error ) go p . connCopy ( conn , relay , errChan ) go p . connCopy ( relay , conn , errChan ) err = <- errChan if err != nil { log . Errorf ( " " , err ) } <- errChan }
ServeTCP forwards the connection to a backend
ServeTCP forwards the connection to a backend