From 8559ae4da117243e870e28846dd3b505ab174d8c Mon Sep 17 00:00:00 2001 From: qydysky Date: Sun, 14 Apr 2024 15:03:05 +0000 Subject: [PATCH] 1 --- Net.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/Net.go b/Net.go index 5446d4a..107b9b8 100644 --- a/Net.go +++ b/Net.go @@ -14,7 +14,6 @@ import ( "github.com/miekg/dns" pool "github.com/qydysky/part/pool" - psync "github.com/qydysky/part/sync" ) var ( @@ -365,8 +364,7 @@ func (t udpLis) Addr() net.Addr { } type ConnPool struct { - connMap *psync.Map - pool *pool.Buf[ConnPoolItem] + pool *pool.Buf[ConnPoolItem] } type ConnPoolItem struct { @@ -376,7 +374,6 @@ type ConnPoolItem struct { func NewConnPool(size int, genConn func() *net.Conn) *ConnPool { return &ConnPool{ - connMap: new(psync.Map), pool: pool.New(pool.PoolFunc[ConnPoolItem]{ New: func() *ConnPoolItem { return &ConnPoolItem{p: genConn()} @@ -397,15 +394,9 @@ func NewConnPool(size int, genConn func() *net.Conn) *ConnPool { } func (t *ConnPool) Get(id string) (i net.Conn, putBack func()) { - if conn, ok := t.connMap.LoadV(id).(*ConnPoolItem); ok { - return *conn.p, func() {} - } else { - conn = t.pool.Get() - t.connMap.Store(id, conn) - return *conn.p, func() { - t.connMap.Delete(id) - t.pool.Put(conn) - } + conn := t.pool.Get() + return *conn.p, func() { + t.pool.Put(conn) } } -- 2.39.2