Commit 80fe2e6e authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net: lazily look up the listenerBacklog value on first use

Don't open files or do sysctls in init.

Updates #26775

Change-Id: I017bed6c24ef1e4bc30040120349fb779f203225
Reviewed-on: https://go-review.googlesource.com/127655Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 82724848
......@@ -357,7 +357,16 @@ type PacketConn interface {
SetWriteDeadline(t time.Time) error
}
var listenerBacklog = maxListenerBacklog()
var listenerBacklogCache struct {
sync.Once
val int
}
// listenerBacklog is a caching wrapper around maxListenerBacklog.
func listenerBacklog() int {
listenerBacklogCache.Do(func() { listenerBacklogCache.val = maxListenerBacklog() })
return listenerBacklogCache.val
}
// A Listener is a generic network listener for stream-oriented protocols.
//
......
......@@ -54,7 +54,7 @@ func socket(ctx context.Context, net string, family, sotype, proto int, ipv6only
if laddr != nil && raddr == nil {
switch sotype {
case syscall.SOCK_STREAM, syscall.SOCK_SEQPACKET:
if err := fd.listenStream(laddr, listenerBacklog, ctrlFn); err != nil {
if err := fd.listenStream(laddr, listenerBacklog(), ctrlFn); err != nil {
fd.Close()
return nil, err
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment