Retro68/gcc/libgo/go/net/sock_bsd.go

40 lines
918 B
Go
Raw Normal View History

// Copyright 2009 The Go Authors. All rights reserved.
2012-03-27 23:13:14 +00:00
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build darwin || dragonfly || freebsd || netbsd || openbsd
2012-03-27 23:13:14 +00:00
package net
import (
"runtime"
"syscall"
)
func maxListenerBacklog() int {
var (
n uint32
err error
)
switch runtime.GOOS {
case "darwin", "ios":
2012-03-27 23:13:14 +00:00
n, err = syscall.SysctlUint32("kern.ipc.somaxconn")
2018-12-28 15:30:48 +00:00
case "freebsd":
n, err = syscall.SysctlUint32("kern.ipc.soacceptqueue")
2012-03-27 23:13:14 +00:00
case "netbsd":
// NOTE: NetBSD has no somaxconn-like kernel state so far
case "openbsd":
n, err = syscall.SysctlUint32("kern.somaxconn")
}
if n == 0 || err != nil {
return syscall.SOMAXCONN
}
2014-09-21 17:33:12 +00:00
// FreeBSD stores the backlog in a uint16, as does Linux.
// Assume the other BSDs do too. Truncate number to avoid wrapping.
// See issue 5030.
if n > 1<<16-1 {
n = 1<<16 - 1
2012-03-27 23:13:14 +00:00
}
2014-09-21 17:33:12 +00:00
return int(n)
2012-03-27 23:13:14 +00:00
}