mirror of https://github.com/cbeuw/Cloak
Close connections properly
This commit is contained in:
parent
254b7152b6
commit
e5bda61587
|
|
@ -138,12 +138,12 @@ func RouteTCP(localConfig localConnConfig, newSeshFunc func() *mux.Session) {
|
|||
}
|
||||
go func() {
|
||||
if _, err := common.Copy(localConn, stream, 0); err != nil {
|
||||
log.Debugf("copying stream to proxy client: %v", err)
|
||||
log.Tracef("copying stream to proxy client: %v", err)
|
||||
}
|
||||
}()
|
||||
//util.Pipe(stream, localConn, localConfig.Timeout)
|
||||
if _, err = common.Copy(stream, localConn, localConfig.Timeout); err != nil {
|
||||
log.Debugf("copying proxy client to stream: %v", err)
|
||||
log.Tracef("copying proxy client to stream: %v", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ func Copy(dst net.Conn, src net.Conn, srcReadTimeout time.Duration) (written int
|
|||
//}
|
||||
for {
|
||||
if srcReadTimeout != 0 {
|
||||
// TODO: don't rely on setreaddeadline
|
||||
err = src.SetReadDeadline(time.Now().Add(srcReadTimeout))
|
||||
if err != nil {
|
||||
break
|
||||
|
|
@ -96,5 +97,7 @@ func Copy(dst net.Conn, src net.Conn, srcReadTimeout time.Duration) (written int
|
|||
break
|
||||
}
|
||||
}
|
||||
src.Close()
|
||||
dst.Close()
|
||||
return written, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ func (s *Stream) Write(in []byte) (n int, err error) {
|
|||
if len(in) <= maxDataLen {
|
||||
payload = in
|
||||
} else {
|
||||
//TODO: short write isn't the correct behaviour
|
||||
payload = in[:maxDataLen]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -175,12 +175,12 @@ func DispatchConnection(conn net.Conn, sta *State) {
|
|||
|
||||
go func() {
|
||||
if _, err := common.Copy(localConn, newStream, sta.Timeout); err != nil {
|
||||
log.Debugf("copying stream to proxy client: %v", err)
|
||||
log.Tracef("copying stream to proxy client: %v", err)
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
if _, err := common.Copy(newStream, localConn, 0); err != nil {
|
||||
log.Debugf("copying proxy client to stream: %v", err)
|
||||
log.Tracef("copying proxy client to stream: %v", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue