diff --git a/metrics/wrapper/listener.go b/metrics/wrapper/listener.go index f32efa7d..7ca4c581 100644 --- a/metrics/wrapper/listener.go +++ b/metrics/wrapper/listener.go @@ -2,6 +2,8 @@ package wrapper import ( "net" + + xmetrics "github.com/go-gost/x/metrics" ) type listener struct { @@ -10,10 +12,11 @@ type listener struct { } // WrapListener wraps a net.Listener so that all accepted connections are -// automatically wrapped with WrapConn for metrics tracking. If ln is nil, -// nil is returned. +// automatically wrapped with WrapConn for metrics tracking. If metrics are +// not enabled, ln is returned unchanged to allow splice(2) optimization +// on bare *net.TCPConn. If ln is nil, nil is returned. func WrapListener(service string, ln net.Listener) net.Listener { - if ln == nil { + if ln == nil || !xmetrics.IsEnabled() { return ln } return &listener{