Merge lp:~sergiusens/go-dbus/sequential_writes into lp:go-dbus/v1

Proposed by Sergio Schvezov
Status: Merged
Approved by: John Lenton
Approved revision: 130
Merged at revision: 129
Proposed branch: lp:~sergiusens/go-dbus/sequential_writes
Merge into: lp:go-dbus/v1
Diff against target: 75 lines (+15/-0)
3 files modified
auth.go (+6/-0)
message.go (+7/-0)
transport.go (+2/-0)
To merge this branch: bzr merge lp:~sergiusens/go-dbus/sequential_writes
Reviewer Review Type Date Requested Status
John Lenton Approve
Review via email: mp+239227@code.launchpad.net

Commit message

Making message writing sequential to avoid multiple messages writing to the bus at the same time

To post a comment you must log in.
Revision history for this message
John Lenton (chipaca) wrote :

LGTM.

review: Approve
Revision history for this message
Roberto Alsina (ralsina) wrote :

Needs fixing because "doesn't not need" is not a reasonable comment :-)

130. By Sergio Schvezov

Fixing double negation

Revision history for this message
Roberto Alsina (ralsina) wrote :

There's still a couple double negations, lines 17, 26 of the diff.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'auth.go'
2--- auth.go 2013-03-09 04:13:25 +0000
3+++ auth.go 2014-10-22 21:48:46 +0000
4@@ -115,6 +115,8 @@
5 }
6
7 // The authentication process starts by writing a nul byte
8+ // writing at this point does not need to be synced as the connection
9+ // is not shared at this point.
10 if _, err := conn.Write([]byte{0}); err != nil {
11 return err
12 }
13@@ -122,6 +124,8 @@
14 inStream := bufio.NewReader(conn)
15 send := func(command ...[]byte) ([][]byte, error) {
16 msg := bytes.Join(command, []byte(" "))
17+ // writing at this point doesn't not need to be synced as the connection
18+ // is not shared at this point.
19 _, err := conn.Write(append(msg, []byte("\r\n")...))
20 if err != nil {
21 return nil, err
22@@ -178,6 +182,8 @@
23 return errors.New("Could not authenticate with any mechanism")
24 }
25 // XXX: UNIX FD negotiation would go here.
26+ // writing at this point doesn't not need to be synced as the connection
27+ // is not shared at this point.
28 if _, err := conn.Write([]byte("BEGIN\r\n")); err != nil {
29 return err
30 }
31
32=== modified file 'message.go'
33--- message.go 2013-03-12 07:20:42 +0000
34+++ message.go 2014-10-22 21:48:46 +0000
35@@ -4,6 +4,7 @@
36 "encoding/binary"
37 "errors"
38 "io"
39+ "sync"
40 )
41
42 // See the D-Bus tutorial for information about message types.
43@@ -26,6 +27,8 @@
44 TypeError: "error",
45 }
46
47+var writeMutex sync.Mutex
48+
49 func (t MessageType) String() string { return messageTypeString[t] }
50
51 type MessageFlag uint8
52@@ -319,6 +322,10 @@
53
54 // WriteTo serialises the message and writes it to the given writer.
55 func (p *Message) WriteTo(w io.Writer) (int64, error) {
56+ // message writing needs to be sequential
57+ writeMutex.Lock()
58+ defer writeMutex.Unlock()
59+
60 fields := make([]headerField, 0, 10)
61 if p.Path != "" {
62 fields = append(fields, headerField{1, Variant{p.Path}})
63
64=== modified file 'transport.go'
65--- transport.go 2013-03-09 04:13:25 +0000
66+++ transport.go 2014-10-22 21:48:46 +0000
67@@ -102,6 +102,8 @@
68 return nil, err
69 }
70 // Write the nonce data to the socket
71+ // writing at this point does not need to be synced as the connection
72+ // is not shared at this point.
73 if _, err := conn.Write(data); err != nil {
74 conn.Close()
75 return nil, err

Subscribers

People subscribed via source and target branches