mirror of
https://github.com/apernet/hysteria.git
synced 2025-04-02 03:57:38 +03:00
chore: minor code tweaks
This commit is contained in:
parent
9cb8cb4f53
commit
3e8c20518d
4 changed files with 5 additions and 7 deletions
|
@ -7,10 +7,9 @@ import (
|
|||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/apernet/hysteria/core/v2/internal/utils"
|
||||
|
||||
"github.com/apernet/hysteria/core/v2/errors"
|
||||
"github.com/apernet/hysteria/core/v2/internal/pmtud"
|
||||
"github.com/apernet/hysteria/core/v2/internal/utils"
|
||||
"github.com/apernet/quic-go"
|
||||
)
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ func copyBufferLog(dst io.Writer, src io.Reader, log func(n uint64) bool) error
|
|||
}
|
||||
}
|
||||
|
||||
func copyTwoWayWithLogger(id string, serverRw, remoteRw io.ReadWriter, l TrafficLogger, stats *StreamStats) error {
|
||||
func copyTwoWayEx(id string, serverRw, remoteRw io.ReadWriter, l TrafficLogger, stats *StreamStats) error {
|
||||
errChan := make(chan error, 2)
|
||||
go func() {
|
||||
errChan <- copyBufferLog(serverRw, remoteRw, func(n uint64) bool {
|
||||
|
@ -52,7 +52,7 @@ func copyTwoWayWithLogger(id string, serverRw, remoteRw io.ReadWriter, l Traffic
|
|||
return <-errChan
|
||||
}
|
||||
|
||||
// copyTwoWay is the "fast-path" version of copyTwoWayWithLogger that does not log traffic.
|
||||
// copyTwoWay is the "fast-path" version of copyTwoWayEx that does not log traffic or update stream stats.
|
||||
// It uses the built-in io.Copy instead of our own copyBufferLog.
|
||||
func copyTwoWay(serverRw, remoteRw io.ReadWriter) error {
|
||||
errChan := make(chan error, 2)
|
||||
|
|
|
@ -280,7 +280,7 @@ func (h *h3sHandler) handleTCPRequest(stream quic.Stream) {
|
|||
}
|
||||
// Start proxying
|
||||
if trafficLogger != nil {
|
||||
err = copyTwoWayWithLogger(h.authID, stream, tConn, trafficLogger, streamStats)
|
||||
err = copyTwoWayEx(h.authID, stream, tConn, trafficLogger, streamStats)
|
||||
} else {
|
||||
// Use the fast path if no traffic logger is set
|
||||
err = copyTwoWay(stream, tConn)
|
||||
|
|
|
@ -11,9 +11,8 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/apernet/quic-go"
|
||||
|
||||
"github.com/apernet/hysteria/core/v2/server"
|
||||
"github.com/apernet/quic-go"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue