From dc21c5ca16dbc43755185ffdf53764c7bb4c3a12 Mon Sep 17 00:00:00 2001 From: Ian Gudger Date: Tue, 29 Oct 2019 17:21:01 -0700 Subject: Add Close and Wait methods to stack. Link endpoints still don't have a unified way to be requested to stop. Updates #837 PiperOrigin-RevId: 277398952 --- pkg/tcpip/stack/stack.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'pkg/tcpip') diff --git a/pkg/tcpip/stack/stack.go b/pkg/tcpip/stack/stack.go index 360c54b2d..6d6ddc0ff 100644 --- a/pkg/tcpip/stack/stack.go +++ b/pkg/tcpip/stack/stack.go @@ -1210,6 +1210,37 @@ func (s *Stack) RestoreCleanupEndpoints(es []TransportEndpoint) { s.mu.Unlock() } +// Close closes all currently registered transport endpoints. +// +// Endpoints created or modified during this call may not get closed. +func (s *Stack) Close() { + for _, e := range s.RegisteredEndpoints() { + e.Close() + } +} + +// Wait waits for all transport and link endpoints to halt their worker +// goroutines. +// +// Endpoints created or modified during this call may not get waited on. +// +// Note that link endpoints must be stopped via an implementation specific +// mechanism. +func (s *Stack) Wait() { + for _, e := range s.RegisteredEndpoints() { + e.Wait() + } + for _, e := range s.CleanupEndpoints() { + e.Wait() + } + + s.mu.RLock() + defer s.mu.RUnlock() + for _, n := range s.nics { + n.linkEP.Wait() + } +} + // Resume restarts the stack after a restore. This must be called after the // entire system has been restored. func (s *Stack) Resume() { -- cgit v1.2.3