From: qydysky Date: Wed, 31 Jul 2024 13:32:30 +0000 (+0800) Subject: Improve 精准的保持牌子 X-Git-Tag: v0.14.14~3 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=3160bd840c03c4d5dabd534670899c52c20c68b5;p=bili_danmu%2F.git Improve 精准的保持牌子 --- diff --git a/Reply/F.go b/Reply/F.go index 02acea7..9be9e33 100644 --- a/Reply/F.go +++ b/Reply/F.go @@ -1017,21 +1017,21 @@ func KeepMedalLight(ctx context.Context, common *c.Common) { h, m, s := time.Now().Clock() now := h*3600 + m*60 + s - if sec > now { - select { - case <-time.After(time.Second * time.Duration(sec-now)): - case <-ctx.Done(): - return - } - } else { - select { - case <-time.After(time.Hour*24 + time.Second*time.Duration(sec-now)): - case <-ctx.Done(): - return + for { + if sec >= now { + select { + case <-time.After(time.Second * time.Duration(sec-now)): + case <-ctx.Done(): + return + } + } else { + select { + case <-time.After(time.Hour*24 + time.Second*time.Duration(sec-now)): + case <-ctx.Done(): + return + } } - } - for { if _, e := keepMedalLight.Main.Run(ctx, keepMedalLight.Func{ Uid: common.Uid, Logg: flog, @@ -1042,11 +1042,6 @@ func KeepMedalLight(ctx context.Context, common *c.Common) { flog.L(`E: `, e) return } - select { - case <-time.After(time.Hour * 24): - case <-ctx.Done(): - return - } } }() } diff --git a/Reply/Reply.go b/Reply/Reply.go index 37b9773..b7ad593 100644 --- a/Reply/Reply.go +++ b/Reply/Reply.go @@ -39,20 +39,17 @@ type brotliDecoder struct { o *bytes.Buffer } -func (t *brotliDecoder) Decode(b *[]byte, offset int) error { +func (t *brotliDecoder) Decode(b []byte, offset int) (buf []byte, err error) { t.inuse.Store(true) - defer t.inuse.Store(false) - - t.i.Reset((*b)[offset:]) + t.i.Reset(b[offset:]) if err := t.d.Reset(t.i); err != nil { - return err + return nil, err } t.o.Reset() if _, err := t.o.ReadFrom(t.d); err != nil { - return err + return nil, err } - *b = append((*b)[:0], t.o.Bytes()...) - return nil + return t.o.Bytes(), nil } var brotliDecoders = pool.New(pool.PoolFunc[brotliDecoder]{ @@ -67,7 +64,10 @@ var brotliDecoders = pool.New(pool.PoolFunc[brotliDecoder]{ return bd.inuse.Load() }, Reuse: func(bd *brotliDecoder) *brotliDecoder { return bd }, - Pool: func(bd *brotliDecoder) *brotliDecoder { return bd }, + Pool: func(bd *brotliDecoder) *brotliDecoder { + bd.inuse.Store(false) + return bd + }, }, 10) // 返回数据分派 @@ -106,8 +106,9 @@ func Reply(common *c.Common, b []byte) { b = buf.Bytes() case c.WS_BODY_PROTOCOL_VERSION_BROTLI: // BROTLI decoder := brotliDecoders.Get() - e := decoder.Decode(&b, 16) - brotliDecoders.Put(decoder) + defer brotliDecoders.Put(decoder) + var e error + b, e = decoder.Decode(b, 16) if e != nil { reply_log.L(`E: `, "解压错误", e) return diff --git a/Reply/flvHeader b/Reply/flvHeader deleted file mode 100644 index 75362c7..0000000 Binary files a/Reply/flvHeader and /dev/null differ