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
17
proxy/io.go
17
proxy/io.go
@ -28,24 +28,17 @@ func ReadBytes(conn *net.TCPConn, dest []byte) ([]byte, error) {
|
||||
return dest[:n], err
|
||||
}
|
||||
|
||||
func readBytesInternal(in io.Reader, dest []byte) (int, error) {
|
||||
totalRead := 0
|
||||
for {
|
||||
numRead, readErr := in.Read(dest[totalRead:])
|
||||
totalRead += numRead
|
||||
if readErr != nil {
|
||||
switch readErr.(type) {
|
||||
func readBytesInternal(conn *net.TCPConn, dest []byte) (int, error) {
|
||||
totalRead, err := conn.Read(dest)
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
case *net.OpError:
|
||||
return totalRead, errors.New("timed out")
|
||||
default:
|
||||
return totalRead, readErr
|
||||
return totalRead, err
|
||||
}
|
||||
}
|
||||
if totalRead == 0 {
|
||||
return 0, io.EOF
|
||||
}
|
||||
return totalRead, nil
|
||||
}
|
||||
}
|
||||
|
||||
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