The concurrent server, which can be achieved with select, is limited by two aspects.
1, a process can open the maximum file descriptor restrictions. This can be done by adjusting the kernel parameters. You can adjust or use the Setrlimit function setting by ulimit-n, but the maximum number that a system can open is also limited, which is related to memory size and can be viewed by Cat/proc/sys/fs/file-max
2, the Fd_set set capacity limit in the Select (Fd_setsize, typically 1024), which requires recompiling the kernel.
You can write a test program that only establishes a connection to see how many connections can be established, and the client program is as follows:
#include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/ inet.h> #include <signal.h> #include <stdlib.h> #include <stdio.h> #include <errno.h> #inc Lude <string.h> #define ERR_EXIT (m) \ do \ {\ perror (m); \ Exi T (exit_failure);
\} while (0) int main (void) {int count = 0;
while (1) {int sock;
if ((sock = socket (pf_inet, Sock_stream, ipproto_tcp)) < 0) {sleep (4);
Err_exit ("socket");
} struct sockaddr_in servaddr;
memset (&servaddr, 0, sizeof (SERVADDR));
servaddr.sin_family = af_inet;
Servaddr.sin_port = htons (5188);
SERVADDR.SIN_ADDR.S_ADDR = inet_addr ("127.0.0.1");
if (Connect (sock, (struct sockaddr *) &servaddr, sizeof (SERVADDR)) < 0) Err_exit ("Connect"); structSockaddr_in localaddr;
socklen_t Addrlen = sizeof (LOCALADDR);
if (getsockname (sock, struct sockaddr *) &localaddr, &addrlen) < 0) Err_exit ("GetSockName");
printf ("ip=%s port=%d\n", Inet_ntoa (LOCALADDR.SIN_ADDR), Ntohs (Localaddr.sin_port));
printf ("Count =%d\n", ++count);
return 0; }