C语言 SOMAXCONN 在 C 套接字编程中是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18073483/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
what do SOMAXCONN mean in C socket programming?
提问by user2655620
I didn't understand anything about somaxconn in socket programming in C( Linux Ubuntu).I searched through several sites, but all those couldn't help me much.
我对 C(Linux Ubuntu)套接字编程中的 somaxconn 一无所知。我搜索了几个站点,但所有这些都对我没有多大帮助。
listen(sockfd,SOMAXCONN);
Does this mean to listen concurrently to maximum no. of connected sockets?
这是否意味着同时收听最大数量。连接的套接字?
回答by Nerius
#include <sys/socket.h>
int listen (int socket, int backlog);
The backlog argument provides a hint to the implementation which the implementation shall use to limit the number of outstanding connections in the socket's listen queue. Implementations may impose a limit on backlog and silently reduce the specified value. Normally, a larger backlog argument value shall result in a larger or equal length of the listen queue. Implementations shall support values of backlog up to
SOMAXCONN, defined in<sys/socket.h>.If
listen()is called with a backlog argument value that is less than 0, the function behaves as if it had been called with a backlog argument value of 0.A backlog argument of 0 may allow the socket to accept connections, in which case the length of the listen queue may be set to an implementation-defined minimum value.
backlog 参数为实现提供了一个提示,实现将使用该提示来限制套接字侦听队列中未完成连接的数量。实现可能会限制积压并默默地减少指定的值。通常,更大的 backlog 参数值将导致更大或相等的侦听队列长度。实现应支持 backlog up to 的值,在 中
SOMAXCONN定义<sys/socket.h>。如果
listen()使用小于 0 的 backlog 参数值调用该函数,则该函数的行为就像使用 backlog 参数值 0 调用它一样。积压参数 0 可能允许套接字接受连接,在这种情况下,侦听队列的长度可以设置为实现定义的最小值。
As seen here.
如这里所见。
回答by iabdalkader
Simply put, the backlog is the maximum number of queued connections you want on a socket.. This queue is there so you can handle a connection from a client while others wait in line, the backlog specifies how long you want this line to be. if more clients attempt to connect to your server, more than the backlog, those connections will be dropped.
简单地说,backlog 是你想要在一个套接字上排队的最大连接数。这个队列在那里,所以你可以处理来自客户端的连接,而其他人排队等待,backlog 指定你希望这条线有多长。如果更多客户端尝试连接到您的服务器,而不是积压,则这些连接将被丢弃。
SOMAXCONNdefines the maximum number you're allowed to pass to listen()which is 128on my system.
SOMAXCONN定义你允许通过的最大数量listen()这是128我的系统上。
You can read more about it in the man page
您可以在手册页中阅读有关它的更多信息

