Skip to content

Commit

Permalink
conn: move booleans to bottom of StdNetBind struct
Browse files Browse the repository at this point in the history
This results in a more compact structure.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
  • Loading branch information
zx2c4 committed Mar 24, 2023
1 parent 6a07b2a commit 6f895be
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions conn/bind_std.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@ var (
// methods for sending and receiving multiple datagrams per-syscall. See the
// proposal in https://github.com/golang/go/issues/45886#issuecomment-1218301564.
type StdNetBind struct {
mu sync.Mutex // protects following fields
ipv4 *net.UDPConn
ipv6 *net.UDPConn
blackhole4 bool
blackhole6 bool
ipv4PC *ipv4.PacketConn // will be nil on non-Linux
ipv6PC *ipv6.PacketConn // will be nil on non-Linux

udpAddrPool sync.Pool // following fields are not guarded by mu
mu sync.Mutex // protects all fields except as specified
ipv4 *net.UDPConn
ipv6 *net.UDPConn
ipv4PC *ipv4.PacketConn // will be nil on non-Linux
ipv6PC *ipv6.PacketConn // will be nil on non-Linux

// these three fields are not guarded by mu
udpAddrPool sync.Pool
ipv4MsgsPool sync.Pool
ipv6MsgsPool sync.Pool

blackhole4 bool
blackhole6 bool
}

func NewStdNetBind() Bind {
Expand Down

0 comments on commit 6f895be

Please sign in to comment.