github.com/roboticscm/goman@v0.0.0-20210203095141-87c07b4a0a55/src/net/sock_bsd.go (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build darwin dragonfly freebsd netbsd openbsd 6 7 package net 8 9 import ( 10 "runtime" 11 "syscall" 12 ) 13 14 func maxListenerBacklog() int { 15 var ( 16 n uint32 17 err error 18 ) 19 switch runtime.GOOS { 20 case "darwin", "freebsd": 21 n, err = syscall.SysctlUint32("kern.ipc.somaxconn") 22 case "netbsd": 23 // NOTE: NetBSD has no somaxconn-like kernel state so far 24 case "openbsd": 25 n, err = syscall.SysctlUint32("kern.somaxconn") 26 } 27 if n == 0 || err != nil { 28 return syscall.SOMAXCONN 29 } 30 // FreeBSD stores the backlog in a uint16, as does Linux. 31 // Assume the other BSDs do too. Truncate number to avoid wrapping. 32 // See issue 5030. 33 if n > 1<<16-1 { 34 n = 1<<16 - 1 35 } 36 return int(n) 37 }