Browse Source

Chore: ignore io timeout

pull/133/head
xjasonlyu 3 years ago
parent
commit
764657d657
  1. 14
      tunnel/tcp.go
  2. 7
      tunnel/udp.go

14
tunnel/tcp.go

@ -72,17 +72,13 @@ func relay(left, right net.Conn) {
wg.Wait()
}
func copyBuffer(dst io.Writer, src io.Reader) (err error) {
func copyBuffer(dst io.Writer, src io.Reader) error {
buf := pool.Get(pool.RelayBufferSize)
defer pool.Put(buf)
defer func() {
if err != nil {
if ne, ok := err.(net.Error); ok && ne.Timeout() {
err = nil /* ignore I/O timeout */
}
}
}()
_, err = io.CopyBuffer(dst, src, buf)
_, err := io.CopyBuffer(dst, src, buf)
if ne, ok := err.(net.Error); ok && ne.Timeout() {
return nil /* ignore I/O timeout */
}
return err
}

7
tunnel/udp.go

@ -86,10 +86,9 @@ func copyPacketBuffer(dst net.PacketConn, src net.PacketConn, to net.Addr, timeo
for {
src.SetReadDeadline(time.Now().Add(timeout))
n, _, err := src.ReadFrom(buf)
if err != nil {
if ne, ok := err.(net.Error); ok && ne.Timeout() {
return nil /* ignore I/O timeout */
}
if ne, ok := err.(net.Error); ok && ne.Timeout() {
return nil /* ignore I/O timeout */
} else if err != nil {
return err
}

Loading…
Cancel
Save