// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package net

import (
	
	
)

// Linux stores the backlog as:
//
//   - uint16 in kernel version < 4.1,
//   - uint32 in kernel version >= 4.1
//
// Truncate number to avoid wrapping.
//
// See issue 5030 and 41470.
func maxAckBacklog( int) int {
	,  := unix.KernelVersion()
	 := 16
	if  > 4 || ( == 4 &&  >= 1) {
		 = 32
	}

	var  uint = 1<< - 1
	if uint() >  {
		 = int()
	}
	return 
}

func maxListenerBacklog() int {
	,  := open("/proc/sys/net/core/somaxconn")
	if  != nil {
		return syscall.SOMAXCONN
	}
	defer .close()
	,  := .readLine()
	if ! {
		return syscall.SOMAXCONN
	}
	 := getFields()
	, ,  := dtoi([0])
	if  == 0 || ! {
		return syscall.SOMAXCONN
	}

	if  > 1<<16-1 {
		return maxAckBacklog()
	}
	return 
}