Skip to content

Commit

Permalink
stream copy print high-level error
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Sep 22, 2019
1 parent 30cca4d commit ade7ee0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
15 changes: 14 additions & 1 deletion client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,20 @@ func handleClient(mux generic.Mux, p1 net.Conn, quiet bool) {
die := make(chan struct{})
go func() {
buf := xmitBuf.Get().([]byte)
generic.CopyBuffer(dst, src, buf)
if _, err := generic.CopyBuffer(dst, src, buf); err != nil {
// error handling
cause := err
if e, ok := err.(interface{ Cause() error }); ok {
cause = e.Cause()
}

switch cause {
case io.EOF:
case io.ErrClosedPipe:
default:
log.Println(err)
}
}
xmitBuf.Put(buf)
close(die)
}()
Expand Down
15 changes: 14 additions & 1 deletion server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,20 @@ func handleClient(p1 io.ReadWriteCloser, p2 net.Conn, quiet bool) {
die := make(chan struct{})
go func() {
buf := xmitBuf.Get().([]byte)
generic.CopyBuffer(dst, src, buf)
if _, err := generic.CopyBuffer(dst, src, buf); err != nil {
// error handling
cause := err
if e, ok := err.(interface{ Cause() error }); ok {
cause = e.Cause()
}

switch cause {
case io.EOF:
case io.ErrClosedPipe:
default:
log.Println(err)
}
}
xmitBuf.Put(buf)
close(die)
}()
Expand Down

0 comments on commit ade7ee0

Please sign in to comment.