what do SOMAXCONN mean in C socket programming?

后端 未结 2 829
南笙
南笙 2021-02-04 03:00

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.

l         


        
相关标签:
2条回答
  • 2021-02-04 03:11
    #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.

    As seen here.

    0 讨论(0)
  • 2021-02-04 03:21

    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.

    SOMAXCONN defines the maximum number you're allowed to pass to listen() which is 128 on my system.

    You can read more about it in the man page

    0 讨论(0)
提交回复
热议问题