Skip to content

Commit

Permalink
Move atomicError type into internal package
Browse files Browse the repository at this point in the history
Move atomicError type into internal package
  • Loading branch information
stv0g committed Feb 10, 2023
1 parent 583ad44 commit 16d645c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
3 changes: 2 additions & 1 deletion agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"sync/atomic"
"time"

atomicx "github.com/pion/ice/v2/internal/atomic"
"github.com/pion/logging"
"github.com/pion/mdns"
"github.com/pion/stun"
Expand Down Expand Up @@ -114,7 +115,7 @@ type Agent struct {
// State for closing
done chan struct{}
taskLoopDone chan struct{}
err atomicError
err atomicx.Error

gatherCandidateCancel func()
gatherCandidateDone chan struct{}
Expand Down
20 changes: 20 additions & 0 deletions internal/atomic/atomic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Package atomic contains custom atomic types
package atomic

import "sync/atomic"

// Error is an atomic error
type Error struct {
v atomic.Value
}

// Store updates the value of the atomic variable
func (a *Error) Store(err error) {
a.v.Store(struct{ error }{err})
}

// Load retrieves the current value of the atomic variable
func (a *Error) Load() error {
err, _ := a.v.Load().(struct{ error })
return err.error
}
12 changes: 0 additions & 12 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,13 @@ package ice
import (
"fmt"
"net"
"sync/atomic"
"time"

"github.com/pion/logging"
"github.com/pion/stun"
"github.com/pion/transport/v2"
)

type atomicError struct{ v atomic.Value }

func (a *atomicError) Store(err error) {
a.v.Store(struct{ error }{err})
}

func (a *atomicError) Load() error {
err, _ := a.v.Load().(struct{ error })
return err.error
}

// The conditions of invalidation written below are defined in
// https://tools.ietf.org/html/rfc8445#section-5.1.1.1
func isSupportedIPv6(ip net.IP) bool {
Expand Down

0 comments on commit 16d645c

Please sign in to comment.