perf: remove loop

This commit is contained in:
Andrey Semenov 2024-08-09 01:52:59 +05:00 committed by LiquidTheDangerous
parent 10d1ee4860
commit dbee4964f8

View File

@ -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) {