summaryrefslogtreecommitdiffhomepage
path: root/pkg/server/grpc_server.go
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-11-12 09:25:56 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-11-12 09:30:20 +0900
commit99556f9cfc2df561dcf7d91c147a129449635224 (patch)
tree7331d768c1cee74ab93041717abd03f9de9702e7 /pkg/server/grpc_server.go
parent289fc39deb9cfa4ee678ff902d51f84c6c828136 (diff)
server: change monitor API design
https://github.com/osrg/gobgp/issues/1763#issuecomment-437594975 Follow Chris's proposal; consistent with the rest of the APIs. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'pkg/server/grpc_server.go')
-rw-r--r--pkg/server/grpc_server.go53
1 files changed, 23 insertions, 30 deletions
diff --git a/pkg/server/grpc_server.go b/pkg/server/grpc_server.go
index 86c756a9..0aac4cf0 100644
--- a/pkg/server/grpc_server.go
+++ b/pkg/server/grpc_server.go
@@ -166,41 +166,34 @@ func (s *server) ListPath(r *api.ListPathRequest, stream api.GobgpApi_ListPathSe
}
func (s *server) MonitorTable(arg *api.MonitorTableRequest, stream api.GobgpApi_MonitorTableServer) error {
- tm, err := s.bgpServer.NewTableMonitor(arg)
- if err != nil {
- return err
- }
- return func() error {
- defer tm.Close()
-
- for v := range tm.Inbox {
- if err := stream.Send(&api.MonitorTableResponse{
- Path: v,
- }); err != nil {
- return err
- }
+ ctx, cancel := context.WithCancel(context.Background())
+ var err error
+ s.bgpServer.MonitorTable(ctx, arg, func(p *api.Path) {
+ if err = stream.Send(&api.MonitorTableResponse{
+ Path: p,
+ }); err != nil {
+ cancel()
+ return
}
- return nil
- }()
+ })
+ <-ctx.Done()
+ return err
}
func (s *server) MonitorPeer(arg *api.MonitorPeerRequest, stream api.GobgpApi_MonitorPeerServer) error {
- pm, err := s.bgpServer.NewPeerMonitor(arg)
- if err != nil {
- return err
- }
- return func() error {
- defer pm.Close()
-
- for v := range pm.Inbox {
- if err := stream.Send(&api.MonitorPeerResponse{
- Peer: v,
- }); err != nil {
- return err
- }
+ ctx, cancel := context.WithCancel(context.Background())
+ var err error
+ err = s.bgpServer.MonitorPeer(ctx, arg, func(p *api.Peer) {
+ if err = stream.Send(&api.MonitorPeerResponse{
+ Peer: p,
+ }); err != nil {
+ fmt.Println("try to cancel")
+ cancel()
+ return
}
- return nil
- }()
+ })
+ <-ctx.Done()
+ return err
}
func (s *server) ResetPeer(ctx context.Context, r *api.ResetPeerRequest) (*empty.Empty, error) {