Ignore:
Timestamp:
Jan 12, 2021, 1:12:24 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
7dafb7b
Parents:
35285fd
Message:

Removed experiment type, server just supports both urls.
Logging is now optional.
Added done flag so spurious invalid accepts are caught.

File:
1 edited

Legend:

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

    r35285fd r481ee28  
    1919        this.pipe[0] = -1;
    2020        this.pipe[1] = -1;
     21        this.done = false;
     22}
     23
     24extern "C" {
     25extern int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
    2126}
    2227
     
    2833        CONNECTION:
    2934        for() {
    30                 printf("=== Accepting connection ===\n");
     35                if( options.log ) printf("=== Accepting connection ===\n");
    3136                int fd = cfa_accept4( this.[sockfd, addr, addrlen, flags], 0, -1`s, &this.cancel, 0p );
     37                // int fd = accept4( this.[sockfd, addr, addrlen, flags] );
    3238                if(fd < 0) {
    3339                        if( errno == ECONNABORTED ) break;
    34                         if( errno == EINVAL ) break;
     40                        if( errno == EINVAL && this.done ) break;
    3541                        abort( "accept error: (%d) %s\n", (int)errno, strerror(errno) );
    3642                }
    3743
    38                 printf("=== New connection %d, waiting for requests ===\n", fd);
     44                if( options.log ) printf("=== New connection %d, waiting for requests ===\n", fd);
    3945                REQUEST:
    4046                for() {
     
    4753                        size_t len = options.socket.buflen;
    4854                        char buffer[len];
    49                         printf("=== Reading request ===\n");
     55                        if( options.log ) printf("=== Reading request ===\n");
    5056                        [code, closed, file, name_size] = http_read(fd, buffer, len, &this.cancel);
    5157
    5258                        // if we are done, break out of the loop
    5359                        if( closed ) {
    54                                 printf("=== Connection closed ===\n");
     60                                if( options.log ) printf("=== Connection closed ===\n");
    5561                                continue CONNECTION;
    5662                        }
     
    5864                        // If this wasn't a request retrun 400
    5965                        if( code != OK200 ) {
    60                                 printf("=== Invalid Request : %d ===\n", code_val(code));
     66                                if( options.log ) printf("=== Invalid Request : %d ===\n", code_val(code));
    6167                                answer_error(fd, code);
    6268                                continue REQUEST;
     
    6470
    6571                        if(0 == strncmp(file, "plaintext", min(name_size, sizeof("plaintext") ))) {
    66                                 printf("=== Request for /plaintext ===\n");
     72                                if( options.log ) printf("=== Request for /plaintext ===\n");
    6773
    6874                                char text[] = "Hello, World!\n";
     
    7278                        }
    7379                        else {
    74                                 printf("=== Request for file %.*s ===\n", (int)name_size, file);
     80                                if( options.log ) printf("=== Request for file %.*s ===\n", (int)name_size, file);
    7581
    7682                                // Get the fd from the file cache
     
    8187                                // If we can't find the file, return 404
    8288                                if( ans_fd < 0 ) {
    83                                         printf("=== File Not Found ===\n");
     89                                        if( options.log ) printf("=== File Not Found ===\n");
    8490                                        answer_error(fd, E404);
    8591                                        continue REQUEST;
     
    9399                        }
    94100
    95                         printf("=== Answer sent ===\n");
     101                        if( options.log ) printf("=== Answer sent ===\n");
    96102                }
    97103        }
Note: See TracChangeset for help on using the changeset viewer.