Close connections properly

This commit is contained in:
Andy Wang 2020-04-09 23:52:08 +01:00
parent 254b7152b6
commit e5bda61587
4 changed files with 8 additions and 4 deletions

View File

@ -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)
}
}()
}

View File

@ -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
}

View File

@ -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]
}

View File

@ -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)
}
}()
}