// Handle handles the connection.
Handle handles the connection.
// Handle handles the connection .
func (t Handler) Handle(cx *layer4.Connection, next layer4.Handler) error {
	pr, pw := io.Pipe()
	nextc := *cx
	nextc.Conn = nextConn{
		Conn:   cx,
		Reader: io.TeeReader(cx, pw),
		pipe:   pw,
	}
	branchc := *cx
	branchc.Conn = teeConn{
		Conn:   cx,
		Reader: pr,
	}
	go func() {
		err := t.compiledChain.Handle(&branchc)
		if err != nil {
			t.logger.Error("handling connection in branch", zap.Error(err))
		}
	}()
	return next.Handle(&nextc)
}
func ( t Handler ) Handle ( cx * layer4 . Connection , next layer4 . Handler ) error { pr , pw := io . Pipe ( ) nextc := * cx nextc . Conn = nextConn { Conn : cx , Reader : io . TeeReader ( cx , pw ) , pipe : pw , } branchc := * cx branchc . Conn = teeConn { Conn : cx , Reader : pr , } go func ( ) { err := t . compiledChain . Handle ( & branchc ) if err != nil { t . logger . Error ( " " , zap . Error ( err ) ) } } ( ) return next . Handle ( & nextc ) }
Handle handles the connection.
Handle handles the connection .
// what is read by the next handler will also be // read by the branch handlers; this is done by // writing conn's reads into a pipe, and having // the branch read from the pipe // this is the conn we pass to the next handler; // anything read by it will be teed into the pipe // (it also needs a pointer to the pipe so it can // close the pipe when the connection closes, // otherwise we'll leak the goroutine, yikes!) // this is the conn we pass to the branch // run the branch concurrently