mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 03:32:33 +08:00
Fix: wrap net.Conn to avoid using *net.TCPConn.(ReadFrom) (#1209)
This commit is contained in:
parent
6f1fb2ffb5
commit
633de52aee
11
common/net/io.go
Normal file
11
common/net/io.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package net
|
||||
|
||||
import "io"
|
||||
|
||||
type ReadOnlyReader struct {
|
||||
io.Reader
|
||||
}
|
||||
|
||||
type WriteOnlyWriter struct {
|
||||
io.Writer
|
||||
}
|
|
@ -10,6 +10,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/Dreamacro/clash/adapters/inbound"
|
||||
N "github.com/Dreamacro/clash/common/net"
|
||||
"github.com/Dreamacro/clash/common/pool"
|
||||
"github.com/Dreamacro/clash/component/resolver"
|
||||
C "github.com/Dreamacro/clash/constant"
|
||||
|
@ -141,14 +142,16 @@ func relay(leftConn, rightConn net.Conn) {
|
|||
|
||||
go func() {
|
||||
buf := pool.Get(pool.RelayBufferSize)
|
||||
_, err := io.CopyBuffer(leftConn, rightConn, buf)
|
||||
// Wrapping to avoid using *net.TCPConn.(ReadFrom)
|
||||
// See also https://github.com/Dreamacro/clash/pull/1209
|
||||
_, err := io.CopyBuffer(N.WriteOnlyWriter{Writer: leftConn}, N.ReadOnlyReader{Reader: rightConn}, buf)
|
||||
pool.Put(buf)
|
||||
leftConn.SetReadDeadline(time.Now())
|
||||
ch <- err
|
||||
}()
|
||||
|
||||
buf := pool.Get(pool.RelayBufferSize)
|
||||
io.CopyBuffer(rightConn, leftConn, buf)
|
||||
io.CopyBuffer(N.WriteOnlyWriter{Writer: rightConn}, N.ReadOnlyReader{Reader: leftConn}, buf)
|
||||
pool.Put(buf)
|
||||
rightConn.SetReadDeadline(time.Now())
|
||||
<-ch
|
||||
|
|
Loading…
Reference in New Issue
Block a user