2016-07-22 20:15:38 +02:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
2011-05-20 02:18:15 +02:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2015-01-15 01:27:56 +01:00
|
|
|
// +build darwin dragonfly freebsd netbsd openbsd
|
2011-10-27 01:57:58 +02:00
|
|
|
|
2011-05-20 02:18:15 +02:00
|
|
|
package net
|
|
|
|
|
|
|
|
import (
|
2012-01-25 21:56:26 +01:00
|
|
|
"runtime"
|
2011-05-20 02:18:15 +02:00
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
2012-01-25 21:56:26 +01:00
|
|
|
func maxListenerBacklog() int {
|
|
|
|
var (
|
|
|
|
n uint32
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
switch runtime.GOOS {
|
2018-01-09 02:23:08 +01:00
|
|
|
case "darwin":
|
2012-01-25 21:56:26 +01:00
|
|
|
n, err = syscall.SysctlUint32("kern.ipc.somaxconn")
|
2018-01-09 02:23:08 +01:00
|
|
|
case "freebsd":
|
2018-02-08 16:30:22 +01:00
|
|
|
n, err = syscall.SysctlUint32("kern.ipc.soacceptqueue")
|
2012-01-25 21:56:26 +01: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
|
2011-05-20 02:18:15 +02:00
|
|
|
}
|
2013-07-16 08:54:42 +02: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-02-09 09:19:58 +01:00
|
|
|
}
|
2013-07-16 08:54:42 +02:00
|
|
|
return int(n)
|
2012-02-09 09:19:58 +01:00
|
|
|
}
|