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
=== modified file 'auth.go'
--- auth.go 2013-03-09 04:13:25 +0000
+++ auth.go 2014-10-22 21:48:46 +0000
@@ -115,6 +115,8 @@
115 }115 }
116116
117 // The authentication process starts by writing a nul byte117 // The authentication process starts by writing a nul byte
118 // writing at this point does not need to be synced as the connection
119 // is not shared at this point.
118 if _, err := conn.Write([]byte{0}); err != nil {120 if _, err := conn.Write([]byte{0}); err != nil {
119 return err121 return err
120 }122 }
@@ -122,6 +124,8 @@
122 inStream := bufio.NewReader(conn)124 inStream := bufio.NewReader(conn)
123 send := func(command ...[]byte) ([][]byte, error) {125 send := func(command ...[]byte) ([][]byte, error) {
124 msg := bytes.Join(command, []byte(" "))126 msg := bytes.Join(command, []byte(" "))
127 // writing at this point doesn't not need to be synced as the connection
128 // is not shared at this point.
125 _, err := conn.Write(append(msg, []byte("\r\n")...))129 _, err := conn.Write(append(msg, []byte("\r\n")...))
126 if err != nil {130 if err != nil {
127 return nil, err131 return nil, err
@@ -178,6 +182,8 @@
178 return errors.New("Could not authenticate with any mechanism")182 return errors.New("Could not authenticate with any mechanism")
179 }183 }
180 // XXX: UNIX FD negotiation would go here.184 // XXX: UNIX FD negotiation would go here.
185 // writing at this point doesn't not need to be synced as the connection
186 // is not shared at this point.
181 if _, err := conn.Write([]byte("BEGIN\r\n")); err != nil {187 if _, err := conn.Write([]byte("BEGIN\r\n")); err != nil {
182 return err188 return err
183 }189 }
184190
=== modified file 'message.go'
--- message.go 2013-03-12 07:20:42 +0000
+++ message.go 2014-10-22 21:48:46 +0000
@@ -4,6 +4,7 @@
4 "encoding/binary"4 "encoding/binary"
5 "errors"5 "errors"
6 "io"6 "io"
7 "sync"
7)8)
89
9// See the D-Bus tutorial for information about message types.10// See the D-Bus tutorial for information about message types.
@@ -26,6 +27,8 @@
26 TypeError: "error",27 TypeError: "error",
27}28}
2829
30var writeMutex sync.Mutex
31
29func (t MessageType) String() string { return messageTypeString[t] }32func (t MessageType) String() string { return messageTypeString[t] }
3033
31type MessageFlag uint834type MessageFlag uint8
@@ -319,6 +322,10 @@
319322
320// WriteTo serialises the message and writes it to the given writer.323// WriteTo serialises the message and writes it to the given writer.
321func (p *Message) WriteTo(w io.Writer) (int64, error) {324func (p *Message) WriteTo(w io.Writer) (int64, error) {
325 // message writing needs to be sequential
326 writeMutex.Lock()
327 defer writeMutex.Unlock()
328
322 fields := make([]headerField, 0, 10)329 fields := make([]headerField, 0, 10)
323 if p.Path != "" {330 if p.Path != "" {
324 fields = append(fields, headerField{1, Variant{p.Path}})331 fields = append(fields, headerField{1, Variant{p.Path}})
325332
=== modified file 'transport.go'
--- transport.go 2013-03-09 04:13:25 +0000
+++ transport.go 2014-10-22 21:48:46 +0000
@@ -102,6 +102,8 @@
102 return nil, err102 return nil, err
103 }103 }
104 // Write the nonce data to the socket104 // Write the nonce data to the socket
105 // writing at this point does not need to be synced as the connection
106 // is not shared at this point.
105 if _, err := conn.Write(data); err != nil {107 if _, err := conn.Write(data); err != nil {
106 conn.Close()108 conn.Close()
107 return nil, err109 return nil, err

Subscribers

People subscribed via source and target branches