Source file
src/net/sock_linux.go
1
2
3
4
5 package net
6
7 import (
8 "internal/syscall/unix"
9 "syscall"
10 )
11
12
13
14
15
16
17
18
19
20 func maxAckBacklog(n int) int {
21 major, minor := unix.KernelVersion()
22 size := 16
23 if major > 4 || (major == 4 && minor >= 1) {
24 size = 32
25 }
26
27 var max uint = 1<<size - 1
28 if uint(n) > max {
29 n = int(max)
30 }
31 return n
32 }
33
34 func maxListenerBacklog() int {
35 fd, err := open("/proc/sys/net/core/somaxconn")
36 if err != nil {
37 return syscall.SOMAXCONN
38 }
39 defer fd.close()
40 l, ok := fd.readLine()
41 if !ok {
42 return syscall.SOMAXCONN
43 }
44 f := getFields(l)
45 n, _, ok := dtoi(f[0])
46 if n == 0 || !ok {
47 return syscall.SOMAXCONN
48 }
49
50 if n > 1<<16-1 {
51 return maxAckBacklog(n)
52 }
53 return n
54 }
55
View as plain text