优化连接管理和日志记录

This commit is contained in:
2025-02-27 23:11:36 +08:00
parent 38d5341e84
commit 037c2c53c6
11 changed files with 436 additions and 403 deletions

View File

@@ -35,7 +35,7 @@ func ChanConnAccept(ctx context.Context, ls net.Listener) chan net.Conn {
return connCh
}
func ChanWgWait(ctx context.Context, wg *CountWaitGroup) chan struct{} {
func ChanWgWait[T WaitGroup](ctx context.Context, wg T) chan struct{} {
ch := make(chan struct{})
go func() {
wg.Wait()

View File

@@ -6,7 +6,7 @@ import (
)
type WaitGroup interface {
Add(delta uint)
Add(delta int)
Done()
Wait()
}
@@ -16,8 +16,8 @@ type CountWaitGroup struct {
num atomic.Int64
}
func (c *CountWaitGroup) Add(delta uint) {
c.wg.Add(int(delta))
func (c *CountWaitGroup) Add(delta int) {
c.wg.Add(delta)
c.num.Add(int64(delta))
}