func (s *StatCounter) Value() uint64 {
	return atomic.LoadUint64(&s.count)
}
Value returns the current value of the counter.
package tcpip
import (
	"errors"
	"fmt"
	"reflect"
	"strconv"
	"strings"
	"sync"
	"sync/atomic"
	"time"
	"github.com/brewlin/net-protocol/pkg/buffer"
	"github.com/brewlin/net-protocol/pkg/waiter"
)
type Error struct {
	msg string
	ignoreStats bool
}
func (e *Error) String() string {
	return e.msg
}
func (e *Error) Error() string {
	return e.msg
}
func (e *Error) IgnoreStats() bool {
	return e.ignoreStats
}
var (
	ErrUnknownProtocol       = &Error{msg: "unknown protocol"}
	ErrUnknownNICID          = &Error{msg: "unknown nic id"}
	ErrUnknownProtocolOption = &Error{msg: "unknown option for protocol"}
	ErrDuplicateNICID        = &Error{msg: "duplicate nic id"}
	ErrDuplicateAddress      = &Error{msg: "duplicate address"}
	ErrNoRoute               = &Error{msg: "no route"}
	ErrBadLinkEndpoint       = &Error{msg: "bad link layer endpoint"}
	ErrAlreadyBound          = &Error{msg: "endpoint already bound", ignoreStats: true}
	ErrInvalidEndpointState  = &Error{msg: "endpoint is in invalid state"}
	ErrAlreadyConnecting     = &Error{msg: "endpoint is already connecting", ignoreStats: true}
	ErrAlreadyConnected      = &Error{msg: "endpoint is already connected", ignoreStats: true}
	ErrNoPortAvailable       = &Error{msg: "no ports are available"}
	ErrPortInUse             = &Error{msg: "port is in use"}
	ErrBadLocalAddress       = &Error{msg: "bad local address"}
	ErrClosedForSend         = &Error{msg: "endpoint is closed for send"}
	ErrClosedForReceive      = &Error{msg: "endpoint is closed for receive"}
	ErrWouldBlock            = &Error{msg: "operation would block", ignoreStats: true}
	ErrConnectionRefused     = &Error{msg: "connection was refused"}
	ErrTimeout               = &Error{msg: "operation timed out"}
	ErrAborted               = &Error{msg: "operation aborted"}
	ErrConnectStarted        = &Error{msg: "connection attempt started", ignoreStats: true}
	ErrDestinationRequired   = &Error{msg: "destination address is required"}
	ErrNotSupported          = &Error{msg: "operation not supported"}
	ErrQueueSizeNotSupported = &Error{msg: "queue size querying not supported"}
	ErrNotConnected          = &Error{msg: "endpoint not connected"}
	ErrConnectionReset       = &Error{msg: "connection reset by peer"}
	ErrConnectionAborted     = &Error{msg: "connection aborted"}
	ErrNoSuchFile            = &Error{msg: "no such file"}
	ErrInvalidOptionValue    = &Error{msg: "invalid option value specified"}
	ErrNoLinkAddress         = &Error{msg: "no remote link address"}
	ErrBadAddress            = &Error{msg: "bad address"}
	ErrNetworkUnreachable    = &Error{msg: "network is unreachable"}
	ErrMessageTooLong        = &Error{msg: "message too long"}
	ErrNoBufferSpace         = &Error{msg: "no buffer space available"}
	ErrControlPortUnreachable = &Error{msg: "Destination unreachable (Port unreachable)"}
	ErrControlPacketTooBig = &Error{msg: "control packet is too big"}
)
var (
	errSubnetLengthMismatch = errors.New("subnet length of address and mask differ")
	errSubnetAddressMasked  = errors.New("subnet address has bits set outside the mask")
)
type ErrSaveRejection struct {
	Err error
}
func (e ErrSaveRejection) Error() string {
	return "save rejected due to unsupported networking state: " + e.Err.Error()
}
type Clock interface {
	NowNanoseconds() int64
	NowMonotonic() int64
}
type Address string
type AddressMask string
func (a AddressMask) String() string {
	return Address(a).String()
}
type Subnet struct {
	address Address
	mask    AddressMask
}
func NewSubnet(a Address, m AddressMask) (Subnet, error) {
	if len(a) != len(m) {
		return Subnet{}, errSubnetLengthMismatch
	}
	for i := 0; i < len(a); i++ {
		if a[i]&^m[i] != 0 {
			return Subnet{}, errSubnetAddressMasked
		}
	}
	return Subnet{a, m}, nil
}
func (s *Subnet) Contains(a Address) bool {
	if len(a) != len(s.address) {
		return false
	}
	for i := 0; i < len(a); i++ {
		if a[i]&s.mask[i] != s.address[i] {
			return false
		}
	}
	return true
}
func (s *Subnet) ID() Address {
	return s.address
}
func (s *Subnet) Bits() (ones int, zeros int) {
	for _, b := range []byte(s.mask) {
		for i := uint(0); i < 8; i++ {
			if b&(1<<i) == 0 {
				zeros++
			} else {
				ones++
			}
		}
	}
	return
}
func (s *Subnet) Prefix() int {
	for i, b := range []byte(s.mask) {
		for j := 7; j >= 0; j-- {
			if b&(1<<uint(j)) == 0 {
				return i*8 + 7 - j
			}
		}
	}
	return len(s.mask) * 8
}
func (s *Subnet) Mask() AddressMask {
	return s.mask
}
type NICID int32
type ShutdownFlags int
const (
	ShutdownRead ShutdownFlags = 1 << iota
	ShutdownWrite
)
type FullAddress struct {
	NIC NICID
	Addr Address
	Port uint16
}
func (fa FullAddress) String() string {
	return fmt.Sprintf("%d:%s:%d", fa.NIC, fa.Addr, fa.Port)
}
type Payload interface {
	Get(size int) ([]byte, *Error)
	Size() int
}
type SlicePayload []byte
func (s SlicePayload) Get(size int) ([]byte, *Error) {
	if size > s.Size() {
		size = s.Size()
	}
	return s[:size], nil
}
func (s SlicePayload) Size() int {
	return len(s)
}
type ControlMessages struct {
	HasTimestamp bool
	Timestamp int64
}
type Endpoint interface {
	Close()
	Read(*FullAddress) (buffer.View, ControlMessages, *Error)
	Write(Payload, WriteOptions) (uintptr, <-chan struct{}, *Error)
	Peek([][]byte) (uintptr, ControlMessages, *Error)
	Connect(address FullAddress) *Error
	Shutdown(flags ShutdownFlags) *Error
	Listen(backlog int) *Error
	Accept() (Endpoint, *waiter.Queue, *Error)
	Bind(address FullAddress, commit func() *Error) *Error
	GetLocalAddress() (FullAddress, *Error)
	GetRemoteAddress() (FullAddress, *Error)
	Readiness(mask waiter.EventMask) waiter.EventMask
	SetSockOpt(opt interface{}) *Error
	GetSockOpt(opt interface{}) *Error
}
type WriteOptions struct {
	To *FullAddress
	More bool
	EndOfRecord bool
}
type ErrorOption struct{}
type SendBufferSizeOption int
type ReceiveBufferSizeOption int
type SendQueueSizeOption int
type ReceiveQueueSizeOption int
type V6OnlyOption int
type NoDelayOption int
type ReuseAddressOption int
type PasscredOption int
type TimestampOption int
type TCPInfoOption struct {
	RTT    time.Duration
	RTTVar time.Duration
}
type KeepaliveEnabledOption int
type KeepaliveIdleOption time.Duration
type KeepaliveIntervalOption time.Duration
type KeepaliveCountOption int
type MulticastTTLOption uint8
type MembershipOption struct {
	NIC           NICID
	InterfaceAddr Address
	MulticastAddr Address
}
type AddMembershipOption MembershipOption
type RemoveMembershipOption MembershipOption
type Route struct {
	Destination Address
	Mask AddressMask
	Gateway Address
	NIC NICID
}
func (r *Route) Match(addr Address) bool {
	if len(addr) != len(r.Destination) {
		return false
	}
	for i := 0; i < len(r.Destination); i++ {
		if (addr[i] & r.Mask[i]) != r.Destination[i] {
			return false
		}
	}
	return true
}
type LinkEndpointID uint64
type TransportProtocolNumber uint32
type NetworkProtocolNumber uint32
type StatCounter struct {
	count uint64
}
func (s *StatCounter) Increment() {
	s.IncrementBy(1)
}