Why does Lighttpd require accept multiple times?

Source: Internet
Author: User

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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.