From: qydysky Date: Fri, 16 May 2025 11:26:40 +0000 (+0800) Subject: Fix date race (#207) X-Git-Tag: v0.18.1~1 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=8c0b8d57ba47c4eec3d342d0d2134047990ced31;p=bili_danmu%2F.git Fix date race (#207) --- diff --git a/CV/Var.go b/CV/Var.go index 6a97476..2fab228 100644 --- a/CV/Var.go +++ b/CV/Var.go @@ -48,39 +48,39 @@ type StreamType struct { } type Common struct { - InIdle bool `json:"-"` //闲置中? - PID int `json:"-"` //进程id - Version string `json:"-"` //版本 - Uid int `json:"-"` //client uid - Login bool `json:"login"` //登陆 - Live []*LiveQn `json:"live"` //直播流链接 - Live_qn int `json:"liveQn"` //当前直播流质量 - Live_want_qn int `json:"-"` //期望直播流质量 - Roomid int `json:"-"` //房间ID - Cookie *syncmap.Map `json:"-"` //Cookie - Title string `json:"title"` //直播标题 - Uname string `json:"uname"` //主播名 - UpUid int `json:"upUid"` //主播uid - Rev float64 `json:"rev"` //营收 - Renqi int `json:"renqi"` //人气 - Watched int `json:"watched"` //观看人数 - OnlineNum int `json:"onlineNum"` //在线人数 - GuardNum int `json:"guardNum"` //舰长数 - ParentAreaID int `json:"parentAreaID"` //父分区 - AreaID int `json:"areaID"` //子分区 - Locked bool `json:"locked"` //直播间封禁 - Note string `json:"note"` //分区排行 - Live_Start_Time time.Time `json:"-"` //直播开始时间 - Liveing bool `json:"liveing"` //是否在直播 - Wearing_FansMedal int `json:"WearingFansMedal"` //当前佩戴的粉丝牌 - Token string `json:"-"` //弹幕钥 - WSURL []string `json:"-"` //弹幕链接 - LiveBuvidUpdated time.Time `json:"-"` //LIVE_BUVID更新时间 - Stream_url *url.URL `json:"-"` //直播Web服务 - Proxy string `json:"-"` //全局代理 - SerLocation int `json:"-"` //服务器时区 - AcceptQn map[int]string `json:"-"` //允许的直播流质量 - Qn map[int]string `json:"-"` //全部直播流质量 + InIdle bool `json:"-"` //闲置中? + PID int `json:"-"` //进程id + Version string `json:"-"` //版本 + Uid int `json:"-"` //client uid + Login bool `json:"login"` //登陆 + Live []*LiveQn `json:"live"` //直播流链接 + Live_qn int `json:"liveQn"` //当前直播流质量 + Live_want_qn int `json:"-"` //期望直播流质量 + Roomid int `json:"-"` //房间ID + Cookie *syncmap.Map `json:"-"` //Cookie + Title string `json:"title"` //直播标题 + Uname string `json:"uname"` //主播名 + UpUid int `json:"upUid"` //主播uid + Rev float64 `json:"rev"` //营收 + Renqi int `json:"renqi"` //人气 + Watched int `json:"watched"` //观看人数 + OnlineNum int `json:"onlineNum"` //在线人数 + GuardNum int `json:"guardNum"` //舰长数 + ParentAreaID int `json:"parentAreaID"` //父分区 + AreaID int `json:"areaID"` //子分区 + Locked bool `json:"locked"` //直播间封禁 + Note string `json:"note"` //分区排行 + Live_Start_Time time.Time `json:"-"` //直播开始时间 + Liveing bool `json:"liveing"` //是否在直播 + Wearing_FansMedal int `json:"-"` //当前佩戴的粉丝牌 + Token string `json:"-"` //弹幕钥 + WSURL []string `json:"-"` //弹幕链接 + LiveBuvidUpdated time.Time `json:"-"` //LIVE_BUVID更新时间 + Stream_url *url.URL `json:"-"` //直播Web服务 + Proxy string `json:"-"` //全局代理 + SerLocation int `json:"-"` //服务器时区 + AcceptQn map[int]string `json:"-"` //允许的直播流质量 + Qn map[int]string `json:"-"` //全部直播流质量 // StreamType StreamType `json:"streamType"` //当前直播流类型 AllStreamType map[string]StreamType `json:"-"` //直播流类型 K_v syncmap.Map `json:"-"` //配置文件 @@ -91,6 +91,12 @@ type Common struct { SerLimit *web.Limits `json:"-"` //Web服务连接限制 StartT time.Time `json:"-"` //启动时间 Cache syncmap.MapExceeded[string, any] `json:"-"` //缓存 + l sync.RWMutex +} + +func (t *Common) Lock() func() { + t.l.Lock() + return t.l.Unlock } func (t *Common) MarshalJSON() ([]byte, error) { diff --git a/F/api.go b/F/api.go index da3411e..1b29037 100644 --- a/F/api.go +++ b/F/api.go @@ -9,7 +9,6 @@ import ( "os" "strconv" "strings" - "sync" "sync/atomic" "time" @@ -216,7 +215,6 @@ var ( type GetFunc struct { *c.Common count atomic.Int32 - l sync.RWMutex } // type cacheItem struct { @@ -229,8 +227,7 @@ func Get(c *c.Common) *GetFunc { } func (t *GetFunc) Get(key string) { - t.l.Lock() - defer t.l.Unlock() + defer t.Lock()() t.get(key) } diff --git a/Reply/Reply.go b/Reply/Reply.go index 9dbfec6..6c1b85d 100644 --- a/Reply/Reply.go +++ b/Reply/Reply.go @@ -115,6 +115,8 @@ func Reply(common *c.Common, b []byte) { } replyFS := replyF{common} + defer replyFS.Lock()() + for len(b) != 0 { head := F.HeadChe(b[:c.WS_PACKAGE_HEADER_TOTAL_LENGTH]) if int(head.PackL) > len(b) {