mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-08-02 16:08:31 +00:00
Merge pull request #234 from riking/patch-4
at least pretend to make Statistics updates thread-safe
This commit is contained in:
commit
7fd7592443
3 changed files with 7 additions and 2 deletions
|
@ -448,12 +448,12 @@ func C2SHandleBunchedCommand(conn *websocket.Conn, client *ClientInfo, msg Clien
|
||||||
go func() {
|
go func() {
|
||||||
result := <-resultCh
|
result := <-resultCh
|
||||||
var reply ClientMessage
|
var reply ClientMessage
|
||||||
|
reply.MessageID = msg.MessageID
|
||||||
if result.Err != nil {
|
if result.Err != nil {
|
||||||
reply.Command = ErrorCommand
|
reply.Command = ErrorCommand
|
||||||
reply.Arguments = result.Err.Error()
|
reply.Arguments = result.Err.Error()
|
||||||
} else {
|
} else {
|
||||||
reply.Command = SuccessCommand
|
reply.Command = SuccessCommand
|
||||||
reply.MessageID = msg.MessageID
|
|
||||||
reply.origArguments = result.Val.(string)
|
reply.origArguments = result.Val.(string)
|
||||||
reply.parseOrigArguments()
|
reply.parseOrigArguments()
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,7 +186,7 @@ func HTTPSayOK(w http.ResponseWriter, _ *http.Request) {
|
||||||
|
|
||||||
// SocketUpgrader is the websocket.Upgrader currently in use.
|
// SocketUpgrader is the websocket.Upgrader currently in use.
|
||||||
var SocketUpgrader = websocket.Upgrader{
|
var SocketUpgrader = websocket.Upgrader{
|
||||||
ReadBufferSize: 1024,
|
ReadBufferSize: 160,
|
||||||
WriteBufferSize: 1024,
|
WriteBufferSize: 1024,
|
||||||
CheckOrigin: func(r *http.Request) bool {
|
CheckOrigin: func(r *http.Request) bool {
|
||||||
return r.Header.Get("Origin") == "" || OriginRegexp.MatchString(r.Header.Get("Origin"))
|
return r.Header.Get("Origin") == "" || OriginRegexp.MatchString(r.Header.Get("Origin"))
|
||||||
|
|
|
@ -12,6 +12,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type StatsData struct {
|
type StatsData struct {
|
||||||
|
updateMu sync.Mutex
|
||||||
|
|
||||||
StatsDataVersion int
|
StatsDataVersion int
|
||||||
|
|
||||||
StartTime time.Time
|
StartTime time.Time
|
||||||
|
@ -114,6 +116,9 @@ func SetBuildStamp(buildTime, buildHash string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateStatsIfNeeded() {
|
func updateStatsIfNeeded() {
|
||||||
|
Statistics.updateMu.Lock()
|
||||||
|
defer Statistics.updateMu.Unlock()
|
||||||
|
|
||||||
if time.Now().Add(-2 * time.Second).After(Statistics.CachedStatsLastUpdate) {
|
if time.Now().Add(-2 * time.Second).After(Statistics.CachedStatsLastUpdate) {
|
||||||
updatePeriodicStats()
|
updatePeriodicStats()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue