...

Source file src/net/sock_bsd.go

Documentation: net

		 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  //go:build darwin || dragonfly || freebsd || netbsd || openbsd
		 6  // +build darwin dragonfly freebsd netbsd openbsd
		 7  
		 8  package net
		 9  
		10  import (
		11  	"runtime"
		12  	"syscall"
		13  )
		14  
		15  func maxListenerBacklog() int {
		16  	var (
		17  		n	 uint32
		18  		err error
		19  	)
		20  	switch runtime.GOOS {
		21  	case "darwin", "ios":
		22  		n, err = syscall.SysctlUint32("kern.ipc.somaxconn")
		23  	case "freebsd":
		24  		n, err = syscall.SysctlUint32("kern.ipc.soacceptqueue")
		25  	case "netbsd":
		26  		// NOTE: NetBSD has no somaxconn-like kernel state so far
		27  	case "openbsd":
		28  		n, err = syscall.SysctlUint32("kern.somaxconn")
		29  	}
		30  	if n == 0 || err != nil {
		31  		return syscall.SOMAXCONN
		32  	}
		33  	// FreeBSD stores the backlog in a uint16, as does Linux.
		34  	// Assume the other BSDs do too. Truncate number to avoid wrapping.
		35  	// See issue 5030.
		36  	if n > 1<<16-1 {
		37  		n = 1<<16 - 1
		38  	}
		39  	return int(n)
		40  }
		41  

View as plain text