1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-02 23:47:07 -05:00

properly start and close outbound handlers

This commit is contained in:
Darien Raymond 2018-02-08 17:24:14 +01:00
parent dffaef60b4
commit 32f1ba7c7e
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -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
}