Fix: wait for device to close

This commit is contained in:
xjasonlyu
2022-03-27 20:44:02 +08:00
parent ba0a4acbda
commit c2af4c0c7c
3 changed files with 12 additions and 5 deletions

View File

@@ -17,4 +17,7 @@ type Device interface {
// Type returns the driver type of the device. // Type returns the driver type of the device.
Type() string Type() string
// Wait waits for the device to close.
Wait()
} }

View File

@@ -79,5 +79,6 @@ func (t *TUN) Name() string {
} }
func (t *TUN) Close() error { func (t *TUN) Close() error {
t.Endpoint.Close()
return t.nt.Close() return t.nt.Close()
} }

View File

@@ -80,13 +80,16 @@ func (e *engine) start() error {
return nil return nil
} }
func (e *engine) stop() error { func (e *engine) stop() (err error) {
if e.device != nil { if e.device != nil {
return e.device.Close() err = e.device.Close()
e.device.Wait()
} }
if e.stack != nil {
e.stack.Close() e.stack.Close()
e.stack.Wait() e.stack.Wait()
return nil }
return err
} }
func (e *engine) insert(k *Key) { func (e *engine) insert(k *Key) {