Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/io/http/worker.cfa

    r97748ee re235429  
    1919        this.pipe[0] = -1;
    2020        this.pipe[1] = -1;
    21         this.done = false;
    22 }
    23 
    24 extern "C" {
    25 extern int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
    2621}
    2722
     
    3328        CONNECTION:
    3429        for() {
    35                 if( options.log ) printf("=== Accepting connection ===\n");
    36                 int fd = cfa_accept4( this.[sockfd, addr, addrlen, flags], 0, -1`s, &this.cancel, 0p );
    37                 // int fd = accept4( this.[sockfd, addr, addrlen, flags] );
     30                int fd = cfa_accept4( this.[sockfd, addr, addrlen, flags], 0, -1`s, 0p, 0p );
    3831                if(fd < 0) {
    3932                        if( errno == ECONNABORTED ) break;
    40                         if( errno == EINVAL && this.done ) break;
    4133                        abort( "accept error: (%d) %s\n", (int)errno, strerror(errno) );
    4234                }
    4335
    44                 if( options.log ) printf("=== New connection %d, waiting for requests ===\n", fd);
     36                printf("New connection %d, waiting for requests\n", fd);
    4537                REQUEST:
    4638                for() {
     
    5345                        size_t len = options.socket.buflen;
    5446                        char buffer[len];
    55                         if( options.log ) printf("=== Reading request ===\n");
    56                         [code, closed, file, name_size] = http_read(fd, buffer, len, &this.cancel);
     47                        printf("Reading request\n");
     48                        [code, closed, file, name_size] = http_read(fd, buffer, len);
    5749
    5850                        // if we are done, break out of the loop
    5951                        if( closed ) {
    60                                 if( options.log ) printf("=== Connection closed ===\n");
    61                                 close(fd);
     52                                printf("Connection closed\n");
    6253                                continue CONNECTION;
    6354                        }
     
    6556                        // If this wasn't a request retrun 400
    6657                        if( code != OK200 ) {
    67                                 printf("=== Invalid Request : %d ===\n", code_val(code));
     58                                printf("Invalid Request : %d\n", code_val(code));
    6859                                answer_error(fd, code);
    6960                                continue REQUEST;
    7061                        }
    7162
    72                         if(0 == strncmp(file, "plaintext", min(name_size, sizeof("plaintext") ))) {
    73                                 if( options.log ) printf("=== Request for /plaintext ===\n");
    74 
    75                                 char text[] = "Hello, World!\n";
    76 
    77                                 // Send the header
    78                                 answer_plain(fd, text, sizeof(text));
    79 
    80                                 if( options.log ) printf("=== Answer sent ===\n");
    81                                 continue REQUEST;
    82                         }
    83 
    84                         if(0 == strncmp(file, "ping", min(name_size, sizeof("ping") ))) {
    85                                 if( options.log ) printf("=== Request for /ping ===\n");
    86 
    87                                 // Send the header
    88                                 answer_empty(fd);
    89 
    90                                 if( options.log ) printf("=== Answer sent ===\n");
    91                                 continue REQUEST;
    92                         }
    93 
    94                         if( options.log ) printf("=== Request for file %.*s ===\n", (int)name_size, file);
     63                        printf("Request for file %.*s\n", (int)name_size, file);
    9564
    9665                        // Get the fd from the file cache
     
    10170                        // If we can't find the file, return 404
    10271                        if( ans_fd < 0 ) {
    103                                 printf("=== File Not Found ===\n");
     72                                printf("File Not Found\n");
    10473                                answer_error(fd, E404);
    10574                                continue REQUEST;
     
    11281                        sendfile( this.pipe, fd, ans_fd, count);
    11382
    114                         if( options.log ) printf("=== Answer sent ===\n");
     83                        printf("File sent\n");
    11584                }
    11685        }
Note: See TracChangeset for help on using the changeset viewer.