In the Lighttpd network model, we can see the following code:
1 /* accept()s at most 100 connections directly 2 * 3 * we jump out after 100 to give the waiting connections a chance */ 4 for (loops = 0; loops < 100 && NULL != (con = connection_accept(srv, srv_socket)); loops++) { 5 handler_t r; 6 7 connection_state_machine(srv, con); 8 9 switch(r = plugins_call_handle_joblist(srv, con)) {10 case HANDLER_FINISHED:11 case HANDLER_GO_ON:12 break;13 default:14 log_error_write(srv, __FILE__, __LINE__, "d", r);15 break;16 }17 }18 return HANDLER_GO_ON;
As the name suggests, when there is a connection, we use select multiplexing, but when we process the connection, we do not know the source and number of events, so we need to make a good loop and judge, this is my guess.
The following code proves that the code is from the server of the sleect model of UNIX network programming.
1 for ( ; ; ) { 2 rset = allset; /* structure assignment */ 3 nready = Select(maxfd+1, &rset, NULL, NULL, NULL); 4 5 if (FD_ISSET(listenfd, &rset)) { /* new client connection */ 6 clilen = sizeof(cliaddr); 7 connfd = Accept(listenfd, (SA *) &cliaddr, &clilen); 8 9 10 printf("new client:1, fd %d\n",connfd);11 sleep(10);12 connfd1 = Accept(listenfd, (SA *) &cliaddr, &clilen);13 printf("new client:2, fd %d\n",connfd1);14 15 sleep(10); 16 return 0;
We deliberately paused for 10 seconds in the middle so that more connections could come in,
Start the server
[[Email protected] tcpcliserv] #./tcpservselect01
At the same time, enter
./Tcpcli01 127.0.0.1
At this time, we can see the output from multiple servers.
New client: 1, FD 4
New client: 2, FD 5
Oh, it proves that our conjecture is correct.
If we do not accept multiple times, we have to wait for the next Select Operation to process. One request, so, is inefficient. If multiple users come in
Why does Lighttpd require accept multiple times?