remove the closeCallback from the session

The closeCallback was run when a session was closed, i.e. after the run
loop of the session stopped. Instead of explicitely calling this callback
from the session, the caller of session.run() can just execute the code
after session.run() returns.
This commit is contained in:
Marten Seemann
2017-04-27 19:10:14 +07:00
parent 5f25ffc795
commit 96e49b0c31
5 changed files with 52 additions and 51 deletions

View File

@@ -244,18 +244,27 @@ func (c *client) createNewSession(negotiatedVersions []protocol.VersionNumber) e
c.version,
c.connectionID,
c.config.TLSConfig,
c.closeCallback,
c.cryptoChangeCallback,
negotiatedVersions)
negotiatedVersions,
)
if err != nil {
return err
}
go c.session.run()
go func() {
// session.run() returns as soon as the session is closed
err := c.session.run()
if err == errCloseSessionForNewVersion {
return
}
c.mutex.Lock()
c.listenErr = err
c.connStateChangeOrErrCond.Signal()
c.mutex.Unlock()
utils.Infof("Connection %x closed.", c.connectionID)
c.conn.Close()
}()
return nil
}
func (c *client) closeCallback(_ protocol.ConnectionID) {
utils.Infof("Connection %x closed.", c.connectionID)
c.conn.Close()
}