mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-12-27 15:45:37 +08:00
Fix initial traffic value
This commit is contained in:
parent
558585b01d
commit
1e787cb607
|
@ -316,18 +316,15 @@ func traffic(trafficManager *trafficontrol.Manager) func(w http.ResponseWriter,
|
||||||
tick := time.NewTicker(time.Second)
|
tick := time.NewTicker(time.Second)
|
||||||
defer tick.Stop()
|
defer tick.Stop()
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
var (
|
uploadTotal, downloadTotal := trafficManager.Total()
|
||||||
uploadTotal int64
|
|
||||||
doanloadTotal int64
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
for range tick.C {
|
for range tick.C {
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
uploadTotalNew, downloadTotalNew := trafficManager.Total()
|
uploadTotalNew, downloadTotalNew := trafficManager.Total()
|
||||||
if err := json.NewEncoder(buf).Encode(Traffic{
|
err := json.NewEncoder(buf).Encode(Traffic{
|
||||||
Up: uploadTotalNew - uploadTotal,
|
Up: uploadTotalNew - uploadTotal,
|
||||||
Down: downloadTotalNew - doanloadTotal,
|
Down: downloadTotalNew - downloadTotal,
|
||||||
}); err != nil {
|
})
|
||||||
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
|
@ -339,8 +336,9 @@ func traffic(trafficManager *trafficontrol.Manager) func(w http.ResponseWriter,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadTotal = uploadTotalNew
|
uploadTotal = uploadTotalNew
|
||||||
doanloadTotal = downloadTotalNew
|
downloadTotal = downloadTotalNew
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,19 +51,10 @@ func (s *CommandServer) handleStatusConn(conn net.Conn) error {
|
||||||
ticker := time.NewTicker(time.Duration(interval))
|
ticker := time.NewTicker(time.Duration(interval))
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
ctx := connKeepAlive(conn)
|
ctx := connKeepAlive(conn)
|
||||||
var (
|
status := s.readStatus()
|
||||||
status StatusMessage
|
uploadTotal := status.UplinkTotal
|
||||||
uploadTotal int64
|
downloadTotal := status.DownlinkTotal
|
||||||
downloadTotal int64
|
|
||||||
)
|
|
||||||
for {
|
for {
|
||||||
status = s.readStatus()
|
|
||||||
upload := status.UplinkTotal - uploadTotal
|
|
||||||
download := status.DownlinkTotal - downloadTotal
|
|
||||||
uploadTotal = status.UplinkTotal
|
|
||||||
downloadTotal = status.DownlinkTotal
|
|
||||||
status.Uplink = upload
|
|
||||||
status.Downlink = download
|
|
||||||
err = binary.Write(conn, binary.BigEndian, status)
|
err = binary.Write(conn, binary.BigEndian, status)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -73,6 +64,13 @@ func (s *CommandServer) handleStatusConn(conn net.Conn) error {
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
}
|
}
|
||||||
|
status = s.readStatus()
|
||||||
|
upload := status.UplinkTotal - uploadTotal
|
||||||
|
download := status.DownlinkTotal - downloadTotal
|
||||||
|
uploadTotal = status.UplinkTotal
|
||||||
|
downloadTotal = status.DownlinkTotal
|
||||||
|
status.Uplink = upload
|
||||||
|
status.Downlink = download
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user