Skip to content

Commit e9c87a8

Browse files
authored
Bunch of small fixes cherry picked out from pluggable-discovery patch in #1333 (#1351)
* Fix discovery client * Fix client_example * Fixed BoardWatch message loop * Upgraded go-properties-orderedmap to v1.5.0
1 parent 97842a8 commit e9c87a8

File tree

9 files changed

+106
-30
lines changed

9 files changed

+106
-30
lines changed

Diff for: arduino/discovery/discovery_client/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ github.com/arduino/go-paths-helper v1.6.0 h1:S7/d7DqB9XlnvF9KrgSiGmo2oWKmYW6O/DT
1414
github.com/arduino/go-paths-helper v1.6.0/go.mod h1:V82BWgAAp4IbmlybxQdk9Bpkz8M4Qyx+RAFKaG9NuvU=
1515
github.com/arduino/go-properties-orderedmap v1.3.0 h1:4No/vQopB36e7WUIk6H6TxiSEJPiMrVOCZylYmua39o=
1616
github.com/arduino/go-properties-orderedmap v1.3.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
17+
github.com/arduino/go-properties-orderedmap v1.5.0 h1:istmr13qQN3nneuU3lsqlMvI6jqB3u8QUfVU1tX/t/8=
18+
github.com/arduino/go-properties-orderedmap v1.5.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
1719
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b/go.mod h1:uwGy5PpN4lqW97FiLnbcx+xx8jly5YuPMJWfVwwjJiQ=
1820
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b/go.mod h1:iIPnclBMYm1g32Q5kXoqng4jLhMStReIP7ZxaoUC2y8=
1921
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=

Diff for: arduino/discovery/discovery_client/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func main() {
3737
log.Fatal("Error initializing discovery:", err)
3838
}
3939

40-
if err := disc.Hello(); err != nil {
40+
if err := disc.Run(); err != nil {
4141
log.Fatal("Error starting discovery:", err)
4242
}
4343
if err := disc.Start(); err != nil {

Diff for: client_example/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ replace github.com/arduino/arduino-cli => ../
66

77
require (
88
github.com/arduino/arduino-cli v0.0.0-20200109150215-ffa84fdaab21
9-
google.golang.org/grpc v1.27.0
9+
google.golang.org/grpc v1.37.0
1010
)

Diff for: client_example/go.sum

+53-18
Large diffs are not rendered by default.

Diff for: client_example/main.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -709,9 +709,16 @@ func callBoardListWatch(client rpc.ArduinoCoreServiceClient, instance *rpc.Insta
709709
go func() {
710710
for {
711711
res, err := watchClient.Recv()
712-
if err != nil {
712+
if err == io.EOF {
713+
log.Print("closing board watch connection")
714+
return
715+
} else if err != nil {
713716
log.Fatalf("Board list watch error: %s\n", err)
714717
}
718+
if res.EventType == "error" {
719+
log.Printf("res: %s\n", res.Error)
720+
continue
721+
}
715722

716723
log.Printf("event: %s, address: %s\n", res.EventType, res.Port.Address)
717724
if res.EventType == "add" {

Diff for: commands/daemon/daemon.go

+36-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package daemon
1717

1818
import (
1919
"context"
20+
"fmt"
2021
"io"
2122

2223
"github.com/arduino/arduino-cli/arduino/utils"
@@ -28,6 +29,7 @@ import (
2829
"github.com/arduino/arduino-cli/commands/sketch"
2930
"github.com/arduino/arduino-cli/commands/upload"
3031
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
32+
"github.com/sirupsen/logrus"
3133
)
3234

3335
// ArduinoCoreServerImpl FIXMEDOC
@@ -73,14 +75,37 @@ func (s *ArduinoCoreServerImpl) BoardListWatch(stream rpc.ArduinoCoreService_Boa
7375
return err
7476
}
7577

76-
interrupt := make(chan bool)
78+
if msg.Instance == nil {
79+
err = fmt.Errorf("no instance specified")
80+
stream.Send(&rpc.BoardListWatchResponse{
81+
EventType: "error",
82+
Error: err.Error(),
83+
})
84+
return err
85+
}
86+
87+
interrupt := make(chan bool, 1)
7788
go func() {
78-
msg, err := stream.Recv()
79-
if err != nil {
80-
interrupt <- true
81-
}
82-
if msg != nil {
83-
interrupt <- msg.Interrupt
89+
defer close(interrupt)
90+
for {
91+
msg, err := stream.Recv()
92+
// Handle client closing the stream and eventual errors
93+
if err == io.EOF {
94+
logrus.Info("boards watcher stream closed")
95+
interrupt <- true
96+
return
97+
} else if err != nil {
98+
logrus.Infof("interrupting boards watcher: %v", err)
99+
interrupt <- true
100+
return
101+
}
102+
103+
// Message received, does the client want to interrupt?
104+
if msg != nil && msg.Interrupt {
105+
logrus.Info("boards watcher interrupted by client")
106+
interrupt <- msg.Interrupt
107+
return
108+
}
84109
}
85110
}()
86111

@@ -90,7 +115,10 @@ func (s *ArduinoCoreServerImpl) BoardListWatch(stream rpc.ArduinoCoreService_Boa
90115
}
91116

92117
for event := range eventsChan {
93-
stream.Send(event)
118+
err = stream.Send(event)
119+
if err != nil {
120+
logrus.Infof("sending board watch message: %v", err)
121+
}
94122
}
95123

96124
return nil

Diff for: docsgen/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ github.com/arduino/go-paths-helper v1.6.0 h1:S7/d7DqB9XlnvF9KrgSiGmo2oWKmYW6O/DT
1818
github.com/arduino/go-paths-helper v1.6.0/go.mod h1:V82BWgAAp4IbmlybxQdk9Bpkz8M4Qyx+RAFKaG9NuvU=
1919
github.com/arduino/go-properties-orderedmap v1.3.0 h1:4No/vQopB36e7WUIk6H6TxiSEJPiMrVOCZylYmua39o=
2020
github.com/arduino/go-properties-orderedmap v1.3.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
21+
github.com/arduino/go-properties-orderedmap v1.5.0 h1:istmr13qQN3nneuU3lsqlMvI6jqB3u8QUfVU1tX/t/8=
22+
github.com/arduino/go-properties-orderedmap v1.5.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
2123
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b h1:9hDi4F2st6dbLC3y4i02zFT5quS4X6iioWifGlVwfy4=
2224
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b/go.mod h1:uwGy5PpN4lqW97FiLnbcx+xx8jly5YuPMJWfVwwjJiQ=
2325
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b h1:3PjgYG5gVPA7cipp7vIR2lF96KkEJIFBJ+ANnuv6J20=

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.14
55
require (
66
github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c
77
github.com/arduino/go-paths-helper v1.6.0
8-
github.com/arduino/go-properties-orderedmap v1.3.0
8+
github.com/arduino/go-properties-orderedmap v1.5.0
99
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b
1010
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b
1111
github.com/cmaglie/go.rice v1.0.3 // This one must be kept until https://github.com/GeertJohan/go.rice/pull/159 is merged

Diff for: go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ github.com/arduino/go-paths-helper v1.6.0 h1:S7/d7DqB9XlnvF9KrgSiGmo2oWKmYW6O/DT
2222
github.com/arduino/go-paths-helper v1.6.0/go.mod h1:V82BWgAAp4IbmlybxQdk9Bpkz8M4Qyx+RAFKaG9NuvU=
2323
github.com/arduino/go-properties-orderedmap v1.3.0 h1:4No/vQopB36e7WUIk6H6TxiSEJPiMrVOCZylYmua39o=
2424
github.com/arduino/go-properties-orderedmap v1.3.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
25+
github.com/arduino/go-properties-orderedmap v1.5.0 h1:istmr13qQN3nneuU3lsqlMvI6jqB3u8QUfVU1tX/t/8=
26+
github.com/arduino/go-properties-orderedmap v1.5.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
2527
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b h1:9hDi4F2st6dbLC3y4i02zFT5quS4X6iioWifGlVwfy4=
2628
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b/go.mod h1:uwGy5PpN4lqW97FiLnbcx+xx8jly5YuPMJWfVwwjJiQ=
2729
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b h1:3PjgYG5gVPA7cipp7vIR2lF96KkEJIFBJ+ANnuv6J20=

0 commit comments

Comments
 (0)