diagnostics: remove duplicate copies of diagnostic_kind_text
[official-gcc.git] / libgo / go / net / sock_bsd.go
blob27daf722b53466318304097a043ae9e93d1431f4
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.
5 //go:build darwin || dragonfly || freebsd || netbsd || openbsd
7 package net
9 import (
10 "runtime"
11 "syscall"
14 func maxListenerBacklog() int {
15 var (
16 n uint32
17 err error
19 switch runtime.GOOS {
20 case "darwin", "ios":
21 n, err = syscall.SysctlUint32("kern.ipc.somaxconn")
22 case "freebsd":
23 n, err = syscall.SysctlUint32("kern.ipc.soacceptqueue")
24 case "netbsd":
25 // NOTE: NetBSD has no somaxconn-like kernel state so far
26 case "openbsd":
27 n, err = syscall.SysctlUint32("kern.somaxconn")
29 if n == 0 || err != nil {
30 return syscall.SOMAXCONN
32 // FreeBSD stores the backlog in a uint16, as does Linux.
33 // Assume the other BSDs do too. Truncate number to avoid wrapping.
34 // See issue 5030.
35 if n > 1<<16-1 {
36 n = 1<<16 - 1
38 return int(n)