connection: add a close method

and use it instead of netConn directly
This commit is contained in:
Nicola Murino 2019-09-11 12:46:21 +02:00
parent 784f75f45b
commit 9794ca7ee0
2 changed files with 8 additions and 7 deletions

View file

@ -579,6 +579,10 @@ func (c Connection) createMissingDirs(filePath string) error {
return nil return nil
} }
func (c Connection) close() error {
return c.netConn.Close()
}
func getOSOpenFlags(requestFlags sftp.FileOpenFlags) (flags int) { func getOSOpenFlags(requestFlags sftp.FileOpenFlags) (flags int) {
var osFlags int var osFlags int
if requestFlags.Read && requestFlags.Write { if requestFlags.Read && requestFlags.Write {

View file

@ -173,8 +173,8 @@ func CloseActiveConnection(connectionID string) bool {
defer mutex.RUnlock() defer mutex.RUnlock()
for _, c := range openConnections { for _, c := range openConnections {
if c.ID == connectionID { if c.ID == connectionID {
err := c.netConn.Close() err := c.close()
c.Log(logger.LevelDebug, logSender, "close connection requested, err: %v", err) c.Log(logger.LevelDebug, logSender, "close connection requested, close err: %v", err)
result = true result = true
break break
} }
@ -254,11 +254,8 @@ func CheckIdleConnections() {
} }
} }
if idleTime > idleTimeout { if idleTime > idleTimeout {
c.Log(logger.LevelInfo, logSender, "close idle connection, idle time: %v", idleTime) err := c.close()
err := c.netConn.Close() c.Log(logger.LevelInfo, logSender, "close idle connection, idle time: %v, close error: %v", idleTime, err)
if err != nil {
c.Log(logger.LevelWarn, logSender, "idle connection close failed: %v", err)
}
} }
} }
logger.Debug(logSender, "", "check idle connections ended") logger.Debug(logSender, "", "check idle connections ended")