chore: better close single connection in restful api

This commit is contained in:
wwqgtxx
2023-06-26 18:25:36 +08:00
parent 1cb75350e2
commit 614cc93cac
3 changed files with 21 additions and 18 deletions

View File

@ -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 {
@ -117,5 +124,5 @@ type Snapshot struct {
DownloadTotal int64 `json:"downloadTotal"`
UploadTotal int64 `json:"uploadTotal"`
Connections []*TrackerInfo `json:"connections"`
Memory uint64 `json:"memory"`
Memory uint64 `json:"memory"`
}