From 219a74b118b35af7e42f8d00f0f9440df7a8328d Mon Sep 17 00:00:00 2001 From: bjdgyc Date: Sun, 9 Oct 2022 17:55:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20IpPool?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/sessdata/ip_pool.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/server/sessdata/ip_pool.go b/server/sessdata/ip_pool.go index 57ea969..a8d295f 100644 --- a/server/sessdata/ip_pool.go +++ b/server/sessdata/ip_pool.go @@ -14,11 +14,11 @@ var ( IpPool = &ipPoolConfig{} ipActive = map[string]bool{} // ipKeep and ipLease ipAddr => type - ipLease = map[string]bool{} + ipLease = map[string]bool{} + ipPoolMux sync.Mutex ) type ipPoolConfig struct { - mux sync.Mutex // 计算动态ip Ipv4Gateway net.IP Ipv4Mask net.IP @@ -69,17 +69,18 @@ func getIpLease() { base.Error(err) } // fmt.Println(keepIpMaps) - IpPool.mux.Lock() + ipPoolMux.Lock() + ipLease = map[string]bool{} for _, v := range keepIpMaps { ipLease[v.IpAddr] = true } - IpPool.mux.Unlock() + ipPoolMux.Unlock() } // AcquireIp 获取动态ip func AcquireIp(username, macAddr string) net.IP { - IpPool.mux.Lock() - defer IpPool.mux.Unlock() + ipPoolMux.Lock() + defer ipPoolMux.Unlock() tNow := time.Now() @@ -143,8 +144,8 @@ func AcquireIp(username, macAddr string) net.IP { // 回收ip func ReleaseIp(ip net.IP, macAddr string) { - IpPool.mux.Lock() - defer IpPool.mux.Unlock() + ipPoolMux.Lock() + defer ipPoolMux.Unlock() delete(ipActive, ip.String())