修正启动时并发连接ID冲突的问题

This commit is contained in:
lwch
2021-08-27 14:21:33 +08:00
parent 7523efe6ef
commit 1eaea40a50
+4 -3
View File
@@ -5,6 +5,7 @@ import (
"natpass/code/client/global"
"natpass/code/network"
"sync"
"sync/atomic"
"time"
"github.com/lwch/logging"
@@ -58,12 +59,12 @@ func (p *Pool) Get(id ...string) *Conn {
return conn
}
p.idx++
conn := p.connect(p.idx)
idx := atomic.AddUint32(&p.idx, 1)
conn := p.connect(idx)
if conn == nil {
return nil
}
c := newConn(p, conn, p.idx)
c := newConn(p, conn, idx)
p.Lock()
p.conns[c.Idx] = c