engine: graph, resources: Change Watch to use ctx

This is a general port. There are many optimizations and cleanups we can
do now that we have a proper context passed in. That's for a future
patch.
This commit is contained in:
James Shubin
2023-08-07 20:17:32 -04:00
parent 53a878bf61
commit 963393e3d9
37 changed files with 139 additions and 130 deletions

View File

@@ -21,6 +21,7 @@ package resources
import (
"bytes"
"context"
"fmt"
"io/ioutil"
"net"
@@ -202,7 +203,7 @@ func (obj *NetRes) Close() error {
// Watch listens for events from the specified interface via a netlink socket.
// TODO: currently gets events from ALL interfaces, would be nice to reject
// events from other interfaces.
func (obj *NetRes) Watch() error {
func (obj *NetRes) Watch(ctx context.Context) error {
// create a netlink socket for receiving network interface events
conn, err := socketset.NewSocketSet(rtmGrps, obj.socketFile, unix.NETLINK_ROUTE)
if err != nil {
@@ -299,7 +300,7 @@ func (obj *NetRes) Watch() error {
send = true
case <-obj.init.DoneCtx.Done(): // closed by the engine to signal shutdown
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}