Unverified Commit e9c87a81 authored by Cristian Maglie's avatar Cristian Maglie Committed by GitHub

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
parent 97842a88
......@@ -14,6 +14,8 @@ github.com/arduino/go-paths-helper v1.6.0 h1:S7/d7DqB9XlnvF9KrgSiGmo2oWKmYW6O/DT
github.com/arduino/go-paths-helper v1.6.0/go.mod h1:V82BWgAAp4IbmlybxQdk9Bpkz8M4Qyx+RAFKaG9NuvU=
github.com/arduino/go-properties-orderedmap v1.3.0 h1:4No/vQopB36e7WUIk6H6TxiSEJPiMrVOCZylYmua39o=
github.com/arduino/go-properties-orderedmap v1.3.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
github.com/arduino/go-properties-orderedmap v1.5.0 h1:istmr13qQN3nneuU3lsqlMvI6jqB3u8QUfVU1tX/t/8=
github.com/arduino/go-properties-orderedmap v1.5.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b/go.mod h1:uwGy5PpN4lqW97FiLnbcx+xx8jly5YuPMJWfVwwjJiQ=
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b/go.mod h1:iIPnclBMYm1g32Q5kXoqng4jLhMStReIP7ZxaoUC2y8=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
......
......@@ -37,7 +37,7 @@ func main() {
log.Fatal("Error initializing discovery:", err)
}
if err := disc.Hello(); err != nil {
if err := disc.Run(); err != nil {
log.Fatal("Error starting discovery:", err)
}
if err := disc.Start(); err != nil {
......
......@@ -6,5 +6,5 @@ replace github.com/arduino/arduino-cli => ../
require (
github.com/arduino/arduino-cli v0.0.0-20200109150215-ffa84fdaab21
google.golang.org/grpc v1.27.0
google.golang.org/grpc v1.37.0
)
This diff is collapsed.
......@@ -709,9 +709,16 @@ func callBoardListWatch(client rpc.ArduinoCoreServiceClient, instance *rpc.Insta
go func() {
for {
res, err := watchClient.Recv()
if err != nil {
if err == io.EOF {
log.Print("closing board watch connection")
return
} else if err != nil {
log.Fatalf("Board list watch error: %s\n", err)
}
if res.EventType == "error" {
log.Printf("res: %s\n", res.Error)
continue
}
log.Printf("event: %s, address: %s\n", res.EventType, res.Port.Address)
if res.EventType == "add" {
......
......@@ -17,6 +17,7 @@ package daemon
import (
"context"
"fmt"
"io"
"github.com/arduino/arduino-cli/arduino/utils"
......@@ -28,6 +29,7 @@ import (
"github.com/arduino/arduino-cli/commands/sketch"
"github.com/arduino/arduino-cli/commands/upload"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/sirupsen/logrus"
)
// ArduinoCoreServerImpl FIXMEDOC
......@@ -73,14 +75,37 @@ func (s *ArduinoCoreServerImpl) BoardListWatch(stream rpc.ArduinoCoreService_Boa
return err
}
interrupt := make(chan bool)
if msg.Instance == nil {
err = fmt.Errorf("no instance specified")
stream.Send(&rpc.BoardListWatchResponse{
EventType: "error",
Error: err.Error(),
})
return err
}
interrupt := make(chan bool, 1)
go func() {
msg, err := stream.Recv()
if err != nil {
interrupt <- true
}
if msg != nil {
interrupt <- msg.Interrupt
defer close(interrupt)
for {
msg, err := stream.Recv()
// Handle client closing the stream and eventual errors
if err == io.EOF {
logrus.Info("boards watcher stream closed")
interrupt <- true
return
} else if err != nil {
logrus.Infof("interrupting boards watcher: %v", err)
interrupt <- true
return
}
// Message received, does the client want to interrupt?
if msg != nil && msg.Interrupt {
logrus.Info("boards watcher interrupted by client")
interrupt <- msg.Interrupt
return
}
}
}()
......@@ -90,7 +115,10 @@ func (s *ArduinoCoreServerImpl) BoardListWatch(stream rpc.ArduinoCoreService_Boa
}
for event := range eventsChan {
stream.Send(event)
err = stream.Send(event)
if err != nil {
logrus.Infof("sending board watch message: %v", err)
}
}
return nil
......
......@@ -18,6 +18,8 @@ github.com/arduino/go-paths-helper v1.6.0 h1:S7/d7DqB9XlnvF9KrgSiGmo2oWKmYW6O/DT
github.com/arduino/go-paths-helper v1.6.0/go.mod h1:V82BWgAAp4IbmlybxQdk9Bpkz8M4Qyx+RAFKaG9NuvU=
github.com/arduino/go-properties-orderedmap v1.3.0 h1:4No/vQopB36e7WUIk6H6TxiSEJPiMrVOCZylYmua39o=
github.com/arduino/go-properties-orderedmap v1.3.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
github.com/arduino/go-properties-orderedmap v1.5.0 h1:istmr13qQN3nneuU3lsqlMvI6jqB3u8QUfVU1tX/t/8=
github.com/arduino/go-properties-orderedmap v1.5.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b h1:9hDi4F2st6dbLC3y4i02zFT5quS4X6iioWifGlVwfy4=
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b/go.mod h1:uwGy5PpN4lqW97FiLnbcx+xx8jly5YuPMJWfVwwjJiQ=
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b h1:3PjgYG5gVPA7cipp7vIR2lF96KkEJIFBJ+ANnuv6J20=
......
......@@ -5,7 +5,7 @@ go 1.14
require (
github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c
github.com/arduino/go-paths-helper v1.6.0
github.com/arduino/go-properties-orderedmap v1.3.0
github.com/arduino/go-properties-orderedmap v1.5.0
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b
github.com/cmaglie/go.rice v1.0.3 // This one must be kept until https://github.com/GeertJohan/go.rice/pull/159 is merged
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment