Merge lp:~chipaca/go-dbus/fix-1408668 into lp:go-dbus/v1

Proposed by John Lenton
Status: Merged
Merged at revision: 135
Proposed branch: lp:~chipaca/go-dbus/fix-1408668
Merge into: lp:go-dbus/v1
Diff against target: 69 lines (+23/-7)
1 file modified
dbus.go (+23/-7)
To merge this branch: bzr merge lp:~chipaca/go-dbus/fix-1408668
Reviewer Review Type Date Requested Status
Michael Vogt (community) Approve
Go D-Bus Hackers Pending
Review via email: mp+247611@code.launchpad.net

Commit message

Ignore read errors if the connection has been explicitly closed.

Description of the change

Ignore read errors if the connection has been explicitly closed.

To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote :

Looks good to me!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'dbus.go'
2--- dbus.go 2014-11-19 19:24:28 +0000
3+++ dbus.go 2015-01-26 16:27:21 +0000
4@@ -35,11 +35,13 @@
5 // Connection represents a connection to a message bus.
6 type Connection struct {
7 // The unique name of this connection on the message bus.
8- UniqueName string
9- conn net.Conn
10- writeLock sync.Mutex
11- busProxy BusDaemon
12- lastSerial uint32
13+ UniqueName string
14+ conn net.Conn
15+ writeLock sync.Mutex
16+ busProxy BusDaemon
17+ lastSerial uint32
18+ connOpen bool
19+ connOpenLock sync.Mutex
20
21 handlerMutex sync.Mutex // covers the next three
22 messageFilters []*MessageFilter
23@@ -120,9 +122,10 @@
24 if bus.conn, err = trans.Dial(); err != nil {
25 return nil, err
26 }
27+ bus.setConnOpen(true)
28
29 if err = authenticate(bus.conn, nil); err != nil {
30- bus.conn.Close()
31+ bus.Close()
32 return nil, err
33 }
34
35@@ -142,6 +145,18 @@
36 return bus, nil
37 }
38
39+func (p *Connection) setConnOpen(o bool) {
40+ p.connOpenLock.Lock()
41+ defer p.connOpenLock.Unlock()
42+ p.connOpen = o
43+}
44+
45+func (p *Connection) isConnOpen() bool {
46+ p.connOpenLock.Lock()
47+ defer p.connOpenLock.Unlock()
48+ return p.connOpen
49+}
50+
51 func (p *Connection) Authenticate() error {
52 log.Println("dbus.Connection.Authenticate() is deprecated. This call can be removed")
53 return nil
54@@ -151,7 +166,7 @@
55 for {
56 msg, err := readMessage(p.conn)
57 if err != nil {
58- if err != io.EOF {
59+ if err != io.EOF && p.isConnOpen() {
60 log.Println("Failed to read message:", err)
61 }
62 break
63@@ -245,6 +260,7 @@
64 }
65
66 func (p *Connection) Close() error {
67+ p.setConnOpen(false)
68 return p.conn.Close()
69 }
70

Subscribers

People subscribed via source and target branches

to all changes: