mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2024-12-30 02:37:01 +00:00
Chore: ignore io timeout
This commit is contained in:
+5
-9
@@ -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
|
||||
}
|
||||
|
||||
+3
-4
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user