Skip to content

Commit

Permalink
Use atomic.Value to maintain Go 1.13 compatibility
Browse files Browse the repository at this point in the history
Updates to use atomic.Value in place of atomic.Bool such that older Go
versions can continue to be supported.

Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
  • Loading branch information
hasheddan committed Sep 5, 2023
1 parent 60064c6 commit 70caf30
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions internal/net/udp/packet_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (l *listener) Close() error {
}
// If we haven't already removed the remote address, remove it
// from the connection map.
if !c.rmraddr.Load() {
if c.rmraddr.Load() == nil {
delete(l.conns, c.raddr.String())
c.rmraddr.Store(true)
}
Expand Down Expand Up @@ -268,7 +268,7 @@ type PacketConn struct {
listener *listener

raddr net.Addr
rmraddr atomic.Bool
rmraddr atomic.Value // bool
id atomic.Value

buffer *idtlsnet.PacketBuffer
Expand Down Expand Up @@ -327,7 +327,7 @@ func (c *PacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
// resulting in the remote address entry being dropped prior to the
// "real" client transitioning to sending using the alternate
// identifier.
if id != nil && !c.rmraddr.Load() && addr.String() != c.raddr.String() {
if id != nil && c.rmraddr.Load() == nil && addr.String() != c.raddr.String() {
c.listener.connLock.Lock()
delete(c.listener.conns, c.raddr.String())
c.rmraddr.Store(true)
Expand Down Expand Up @@ -357,7 +357,7 @@ func (c *PacketConn) Close() error {
}
// If we haven't already removed the remote address, remove it from the
// connection map.
if !c.rmraddr.Load() {
if c.rmraddr.Load() == nil {
delete(c.listener.conns, c.raddr.String())
c.rmraddr.Store(true)
}
Expand Down

0 comments on commit 70caf30

Please sign in to comment.