Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use atomic.Value to maintain Go 1.13 compatibility #582

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 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,8 +268,8 @@ type PacketConn struct {
listener *listener

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

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