tproxy icon indicating copy to clipboard operation
tproxy copied to clipboard

if e != io.EOF judgement of PairedConnection.copyData no needed

Open OnlyPiglet opened this issue 1 year ago • 0 comments

Questions:

in file conn.go, maybe we don't need to judge io.EOF error, because as the io.Copy show that it won't throw an EOF io error

func (c *PairedConnection) copyData(dst io.Writer, src io.Reader, tag string) {
	_, e := io.Copy(dst, src)
	if e != nil && e != io.EOF {
		netOpError, ok := e.(*net.OpError)
		if ok && netOpError.Err.Error() != useOfClosedConn {
			reason := netOpError.Unwrap().Error()
			display.PrintlnWithTime(color.HiRedString("[%d] %s error, %s", c.id, tag, reason))
		}
	}
}

// A successful Copy returns err == nil, not err == EOF. // Because Copy is defined to read from src until EOF, it does // not treat an EOF from Read as an error to be reported.

func Copy(dst Writer, src Reader) (written int64, err error) { return copyBuffer(dst, src, nil) }

How to fix:

maybe this would be cleaner , right?

func (c *PairedConnection) copyData(dst io.Writer, src io.Reader, tag string) {
	_, e := io.Copy(dst, src)
	if e != nil  {
		netOpError, ok := e.(*net.OpError)
		if ok && netOpError.Err.Error() != useOfClosedConn {
			reason := netOpError.Unwrap().Error()
			display.PrintlnWithTime(color.HiRedString("[%d] %s error, %s", c.id, tag, reason))
		}
	}
}

OnlyPiglet avatar May 23 '24 06:05 OnlyPiglet