better handling error from Pipe()

This commit is contained in:
Darien Raymond
2016-11-22 00:17:49 +01:00
parent a9946a2dc1
commit 6804d8f73a
9 changed files with 51 additions and 36 deletions
+8 -17
View File
@@ -2,7 +2,6 @@ package shadowsocks
import (
"errors"
"io"
"sync"
"v2ray.com/core/app"
"v2ray.com/core/common/alloc"
@@ -113,18 +112,14 @@ func (this *Client) Dispatch(destination v2net.Destination, payload *alloc.Buffe
return
}
if err := v2io.Pipe(responseReader, ray.OutboundOutput()); err != nil {
if err != io.EOF {
log.Info("Shadowsocks|Client: Failed to transport all TCP response: ", err)
}
if err := v2io.PipeUntilEOF(responseReader, ray.OutboundOutput()); err != nil {
log.Info("Shadowsocks|Client: Failed to transport all TCP response: ", err)
}
}()
bufferedWriter.SetCached(false)
if err := v2io.Pipe(ray.OutboundInput(), bodyWriter); err != nil {
if err != io.EOF {
log.Info("Shadowsocks|Client: Failed to trasnport all TCP request: ", err)
}
if err := v2io.PipeUntilEOF(ray.OutboundInput(), bodyWriter); err != nil {
log.Info("Shadowsocks|Client: Failed to trasnport all TCP request: ", err)
}
responseMutex.Lock()
@@ -143,10 +138,8 @@ func (this *Client) Dispatch(destination v2net.Destination, payload *alloc.Buffe
User: user,
}
if err := v2io.Pipe(reader, ray.OutboundOutput()); err != nil {
if err != io.EOF {
log.Info("Shadowsocks|Client: Failed to transport all UDP response: ", err)
}
if err := v2io.PipeUntilEOF(reader, ray.OutboundOutput()); err != nil {
log.Info("Shadowsocks|Client: Failed to transport all UDP response: ", err)
}
}()
@@ -159,10 +152,8 @@ func (this *Client) Dispatch(destination v2net.Destination, payload *alloc.Buffe
return errors.New("Shadowsocks|Client: Failed to write payload: " + err.Error())
}
}
if err := v2io.Pipe(ray.OutboundInput(), writer); err != nil {
if err != io.EOF {
log.Info("Shadowsocks|Client: Failed to transport all UDP request: ", err)
}
if err := v2io.PipeUntilEOF(ray.OutboundInput(), writer); err != nil {
log.Info("Shadowsocks|Client: Failed to transport all UDP request: ", err)
}
responseMutex.Lock()
+6 -2
View File
@@ -198,11 +198,15 @@ func (this *Server) handleConnection(conn internet.Connection) {
responseWriter.Write(payload)
bufferedWriter.SetCached(false)
v2io.Pipe(ray.InboundOutput(), responseWriter)
if err := v2io.PipeUntilEOF(ray.InboundOutput(), responseWriter); err != nil {
log.Info("Shadowsocks|Server: Failed to transport all TCP response: ", err)
}
}
}()
v2io.Pipe(bodyReader, ray.InboundInput())
if err := v2io.PipeUntilEOF(bodyReader, ray.InboundInput()); err != nil {
log.Info("Shadowsocks|Server: Failed to transport all TCP request: ", err)
}
ray.InboundInput().Close()
writeFinish.Lock()