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.
|
|
|
|
|
|
|
|
package net
|
|
|
|
|
2012-01-25 21:56:26 +01:00
|
|
|
import "syscall"
|
2011-05-20 02:18:15 +02:00
|
|
|
|
2012-01-25 21:56:26 +01:00
|
|
|
func maxListenerBacklog() int {
|
|
|
|
fd, err := open("/proc/sys/net/core/somaxconn")
|
|
|
|
if err != nil {
|
|
|
|
return syscall.SOMAXCONN
|
|
|
|
}
|
|
|
|
defer fd.close()
|
|
|
|
l, ok := fd.readLine()
|
|
|
|
if !ok {
|
|
|
|
return syscall.SOMAXCONN
|
|
|
|
}
|
|
|
|
f := getFields(l)
|
2017-01-14 01:05:42 +01:00
|
|
|
n, _, ok := dtoi(f[0])
|
2012-01-25 21:56:26 +01:00
|
|
|
if n == 0 || !ok {
|
|
|
|
return syscall.SOMAXCONN
|
2011-05-20 02:18:15 +02:00
|
|
|
}
|
2013-07-16 08:54:42 +02:00
|
|
|
// Linux stores the backlog in a uint16.
|
|
|
|
// 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 n
|
2012-02-09 09:19:58 +01:00
|
|
|
}
|