github.com/epfl-dcsl/gotee@v0.0.0-20200909122901-014b35f5e5e9/src/gnet/sock_linux.go (about) 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. 4 5 package gnet 6 7 import ( 8 "runtime" 9 "syscall" 10 ) 11 12 func maxListenerBacklog() int { 13 //TODO @aghosn, quick fix for debugging. 14 if runtime.IsEnclave() { 15 return 128 16 } 17 fd, err := open("/proc/sys/net/core/somaxconn") 18 if err != nil { 19 return syscall.SOMAXCONN 20 } 21 defer fd.close() 22 l, ok := fd.readLine() 23 if !ok { 24 return syscall.SOMAXCONN 25 } 26 f := getFields(l) 27 n, _, ok := dtoi(f[0]) 28 if n == 0 || !ok { 29 return syscall.SOMAXCONN 30 } 31 // Linux stores the backlog in a uint16. 32 // Truncate number to avoid wrapping. 33 // See issue 5030. 34 if n > 1<<16-1 { 35 n = 1<<16 - 1 36 } 37 return n 38 }