mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 11:42:43 +08:00
chore: better close single connection in restful api
This commit is contained in:
parent
27325ccfab
commit
ea6e63e94c
|
@ -147,7 +147,7 @@ func (pp *proxySetProvider) getSubscriptionInfo() {
|
|||
}
|
||||
|
||||
func (pp *proxySetProvider) closeAllConnections() {
|
||||
statistic.DefaultManager.ConnectionsRange(func(c statistic.Tracker) bool {
|
||||
statistic.DefaultManager.Range(func(c statistic.Tracker) bool {
|
||||
for _, chain := range c.Chains() {
|
||||
if chain == pp.Name() {
|
||||
_ = c.Close()
|
||||
|
|
|
@ -73,18 +73,14 @@ func getConnections(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
func closeConnection(w http.ResponseWriter, r *http.Request) {
|
||||
id := chi.URLParam(r, "id")
|
||||
statistic.DefaultManager.ConnectionsRange(func(c statistic.Tracker) bool {
|
||||
if id == c.ID() {
|
||||
if c := statistic.DefaultManager.Get(id); c != nil {
|
||||
_ = c.Close()
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
render.NoContent(w, r)
|
||||
}
|
||||
|
||||
func closeAllConnections(w http.ResponseWriter, r *http.Request) {
|
||||
statistic.DefaultManager.ConnectionsRange(func(c statistic.Tracker) bool {
|
||||
statistic.DefaultManager.Range(func(c statistic.Tracker) bool {
|
||||
_ = c.Close()
|
||||
return true
|
||||
})
|
||||
|
|
|
@ -46,6 +46,19 @@ func (m *Manager) Leave(c Tracker) {
|
|||
m.connections.Delete(c.ID())
|
||||
}
|
||||
|
||||
func (m *Manager) Get(id string) (c Tracker) {
|
||||
if value, ok := m.connections.Load(id); ok {
|
||||
c = value.(Tracker)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (m *Manager) Range(f func(c Tracker) bool) {
|
||||
m.connections.Range(func(key, value any) bool {
|
||||
return f(value.(Tracker))
|
||||
})
|
||||
}
|
||||
|
||||
func (m *Manager) PushUploaded(size int64) {
|
||||
m.uploadTemp.Add(size)
|
||||
m.uploadTotal.Add(size)
|
||||
|
@ -67,8 +80,8 @@ func (m *Manager) Memory() uint64 {
|
|||
|
||||
func (m *Manager) Snapshot() *Snapshot {
|
||||
var connections []*TrackerInfo
|
||||
m.connections.Range(func(key, value any) bool {
|
||||
connections = append(connections, value.(Tracker).Info())
|
||||
m.Range(func(c Tracker) bool {
|
||||
connections = append(connections, c.Info())
|
||||
return true
|
||||
})
|
||||
return &Snapshot{
|
||||
|
@ -79,12 +92,6 @@ func (m *Manager) Snapshot() *Snapshot {
|
|||
}
|
||||
}
|
||||
|
||||
func (m *Manager) ConnectionsRange(f func(c Tracker) bool) {
|
||||
m.connections.Range(func(key, value any) bool {
|
||||
return f(value.(Tracker))
|
||||
})
|
||||
}
|
||||
|
||||
func (m *Manager) updateMemory() {
|
||||
stat, err := m.process.MemoryInfo()
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue
Block a user