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.
listen(sockfd,SOMAXCONN);
Does this mean to listen concurrently to maximum no. of connected sockets?
The listen() function applies only to stream sockets. It indicates a readiness to accept client connection requests, and creates a connection request queue of length backlog to queue incoming connection requests.
The socket() function shall create an unbound socket in a communications domain, and return a file descriptor that can be used in later function calls that operate on sockets. The socket() function takes the following arguments: domain. Specifies the communications domain in which a socket is to be created.
Add net. core. somaxconn=1024 to /etc/sysctl. conf for it to become permanent (be reapplied after booting).
tcp_max_syn_backlog - INTEGER Maximal number of remembered connection requests, which have not received an acknowledgment from connecting client. The minimal value is 128 for low memory machines, and it will increase in proportion to the memory of machine. If server suffers from overload, try increasing this number.
#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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With