Browse Source

properly start and close outbound handlers

pull/861/head
Darien Raymond 7 years ago
parent
commit
32f1ba7c7e
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
  1. 42
      app/proxyman/outbound/outbound.go

42
app/proxyman/outbound/outbound.go

@ -36,10 +36,44 @@ func New(ctx context.Context, config *proxyman.OutboundConfig) (*Manager, error)
}
// Start implements core.Feature
func (*Manager) Start() error { return nil }
func (m *Manager) Start() error {
m.access.Lock()
defer m.access.Unlock()
m.running = true
for _, h := range m.taggedHandler {
if err := h.Start(); err != nil {
return err
}
}
for _, h := range m.untaggedHandlers {
if err := h.Start(); err != nil {
return err
}
}
return nil
}
// Close implements core.Feature
func (*Manager) Close() error { return nil }
func (m *Manager) Close() error {
m.access.Lock()
defer m.access.Unlock()
m.running = false
for _, h := range m.taggedHandler {
h.Close()
}
for _, h := range m.untaggedHandlers {
h.Close()
}
return nil
}
// GetDefaultHandler implements core.OutboundHandlerManager.
func (m *Manager) GetDefaultHandler() core.OutboundHandler {
@ -78,6 +112,10 @@ func (m *Manager) AddHandler(ctx context.Context, handler core.OutboundHandler)
m.untaggedHandlers = append(m.untaggedHandlers, handler)
}
if m.running {
return handler.Start()
}
return nil
}

Loading…
Cancel
Save