syscall使用详解

https://golang.hotexamples.com/zh/examples/syscall/-/Listen/golang-listen-function-examples.html

1
2
3
4
5
// Set backlog size to the maximum
	if err = syscall.Listen(fd, syscall.SOMAXCONN); err != nil {
		syscall.Close(fd)
		return nil, err
	}

参考c底层源码

1
2
3
4
5
6
7
8
SYSCALL_DEFINE2(listen, int, fd, int, backlog)
{
    // sysctl_somaxconn 是系统变量 net.core.somaxconn 的值
    int somaxconn = sysctl_somaxconn;
    if ((unsigned int)backlog > somaxconn)
        backlog = somaxconn;
    sock->ops->listen(sock, backlog);
}