Skip to content

Commit

Permalink
ble: eliminate race conditions from response handling
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Jun 15, 2017
1 parent cf14909 commit 39104fb
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion platforms/ble/serial_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func NewSerialPort(address string, rid string, tid string) *SerialPort {
// Open opens a connection to a BLE serial device
func (p *SerialPort) Open() (err error) {
p.client = NewClientAdaptor(p.address)

err = p.client.Connect()

// subscribe to response notifications
Expand All @@ -40,13 +41,13 @@ func (p *SerialPort) Read(b []byte) (n int, err error) {
return
}

p.responseMutex.Lock()
n = len(b)
if len(p.responseData) < n {
n = len(p.responseData)
}
copy(b, p.responseData[:n])

p.responseMutex.Lock()
if len(p.responseData) > n {
p.responseData = p.responseData[n:]
} else {
Expand Down

0 comments on commit 39104fb

Please sign in to comment.