mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2024-12-22 14:26:31 +00:00
perf: remove loop
This commit is contained in:
parent
10d1ee4860
commit
dbee4964f8
25
proxy/io.go
25
proxy/io.go
@ -28,24 +28,17 @@ func ReadBytes(conn *net.TCPConn, dest []byte) ([]byte, error) {
|
|||||||
return dest[:n], err
|
return dest[:n], err
|
||||||
}
|
}
|
||||||
|
|
||||||
func readBytesInternal(in io.Reader, dest []byte) (int, error) {
|
func readBytesInternal(conn *net.TCPConn, dest []byte) (int, error) {
|
||||||
totalRead := 0
|
totalRead, err := conn.Read(dest)
|
||||||
for {
|
if err != nil {
|
||||||
numRead, readErr := in.Read(dest[totalRead:])
|
switch err.(type) {
|
||||||
totalRead += numRead
|
case *net.OpError:
|
||||||
if readErr != nil {
|
return totalRead, errors.New("timed out")
|
||||||
switch readErr.(type) {
|
default:
|
||||||
case *net.OpError:
|
return totalRead, err
|
||||||
return totalRead, errors.New("timed out")
|
|
||||||
default:
|
|
||||||
return totalRead, readErr
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if totalRead == 0 {
|
|
||||||
return 0, io.EOF
|
|
||||||
}
|
|
||||||
return totalRead, nil
|
|
||||||
}
|
}
|
||||||
|
return totalRead, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Serve(from *net.TCPConn, to *net.TCPConn, proto string, fd string, td string, timeout int, bufferSize int) {
|
func Serve(from *net.TCPConn, to *net.TCPConn, proto string, fd string, td string, timeout int, bufferSize int) {
|
||||||
|
Loading…
Reference in New Issue
Block a user