Daily bump.
[official-gcc.git] / libgo / go / net / sock_linux.go
blobcc5ce153b368f5f2a380d3761c17bf4336addfd4
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 package net
7 import "syscall"
9 func maxListenerBacklog() int {
10 fd, err := open("/proc/sys/net/core/somaxconn")
11 if err != nil {
12 return syscall.SOMAXCONN
14 defer fd.close()
15 l, ok := fd.readLine()
16 if !ok {
17 return syscall.SOMAXCONN
19 f := getFields(l)
20 n, _, ok := dtoi(f[0], 0)
21 if n == 0 || !ok {
22 return syscall.SOMAXCONN
24 // Linux stores the backlog in a uint16.
25 // Truncate number to avoid wrapping.
26 // See issue 5030.
27 if n > 1<<16-1 {
28 n = 1<<16 - 1
30 return n