Merge lp:~chipaca/ubuntu-push/dry-close into lp:ubuntu-push/automatic

Proposed by John Lenton
Status: Merged
Approved by: John Lenton
Approved revision: 394
Merged at revision: 382
Proposed branch: lp:~chipaca/ubuntu-push/dry-close
Merge into: lp:ubuntu-push/automatic
Diff against target: 59 lines (+16/-11)
1 file modified
client/session/session.go (+16/-11)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/dry-close
Reviewer Review Type Date Requested Status
Samuele Pedroni Approve
Review via email: mp+253508@code.launchpad.net

Commit message

Moving some duplicated code into closeConnection.

To post a comment you must log in.
lp:~chipaca/ubuntu-push/dry-close updated
392. By John Lenton

merged automatic back

393. By John Lenton

move the shutdown code to its own function

394. By John Lenton

you can't always return g() from f even if f and g have the same signature :(

Revision history for this message
Samuele Pedroni (pedronis) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'client/session/session.go'
2--- client/session/session.go 2015-03-19 13:09:37 +0000
3+++ client/session/session.go 2015-03-19 14:15:22 +0000
4@@ -442,6 +442,12 @@
5 if resetCookie {
6 sess.cookie = ""
7 }
8+ sess.closeConnection()
9+ sess.setState(Disconnected)
10+}
11+
12+func (sess *clientSession) closeConnection() {
13+ // *must be called with connLock held*
14 if sess.Connection != nil {
15 sess.Connection.Close()
16 // we ignore Close errors, on purpose (the thinking being that
17@@ -449,7 +455,6 @@
18 // you could do to recover at this stage).
19 sess.Connection = nil
20 }
21- sess.setState(Disconnected)
22 }
23
24 // handle "ping" messages
25@@ -709,8 +714,15 @@
26 return sess.run(sess.doClose, sess.addAuthorization, sess.getHosts, sess.connect, sess.start, sess.loop)
27 }
28
29+func (sess *clientSession) shutdown() {
30+ sess.Log.Infof("session shutting down.")
31+ sess.connLock.Lock()
32+ defer sess.connLock.Unlock()
33+ sess.stopRedial()
34+ sess.closeConnection()
35+}
36+
37 func (sess *clientSession) doKeepConnection() {
38-Loop:
39 for {
40 select {
41 case cmd := <-sess.cmdCh:
42@@ -723,15 +735,8 @@
43 sess.resetCookie()
44 }
45 case <-sess.stopCh:
46- sess.Log.Infof("session shutting down.")
47- sess.connLock.Lock()
48- defer sess.connLock.Unlock()
49- sess.stopRedial()
50- if sess.Connection != nil {
51- sess.Connection.Close()
52- sess.Connection = nil
53- }
54- break Loop
55+ sess.shutdown()
56+ return
57 case n := <-sess.doneCh:
58 // if n == 0, the redialer aborted. If you do
59 // anything other than log it, keep that in mind.

Subscribers

People subscribed via source and target branches