Ignore:
Timestamp:
Jan 13, 2021, 10:23:07 PM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
9153e53
Parents:
bace538 (diff), a00bc5b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

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

    rbace538 r402658b1  
    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                 int fd = cfa_accept4( this.[sockfd, addr, addrlen, flags], 0, -1`s, 0p, 0p );
     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] );
    3138                if(fd < 0) {
    3239                        if( errno == ECONNABORTED ) break;
     40                        if( errno == EINVAL && this.done ) break;
    3341                        abort( "accept error: (%d) %s\n", (int)errno, strerror(errno) );
    3442                }
    3543
    36                 printf("New connection %d, waiting for requests\n", fd);
     44                if( options.log ) printf("=== New connection %d, waiting for requests ===\n", fd);
    3745                REQUEST:
    3846                for() {
     
    4553                        size_t len = options.socket.buflen;
    4654                        char buffer[len];
    47                         printf("Reading request\n");
    48                         [code, closed, file, name_size] = http_read(fd, buffer, len);
     55                        if( options.log ) printf("=== Reading request ===\n");
     56                        [code, closed, file, name_size] = http_read(fd, buffer, len, &this.cancel);
    4957
    5058                        // if we are done, break out of the loop
    5159                        if( closed ) {
    52                                 printf("Connection closed\n");
     60                                if( options.log ) printf("=== Connection closed ===\n");
     61                                close(fd);
    5362                                continue CONNECTION;
    5463                        }
     
    5665                        // If this wasn't a request retrun 400
    5766                        if( code != OK200 ) {
    58                                 printf("Invalid Request : %d\n", code_val(code));
     67                                printf("=== Invalid Request : %d ===\n", code_val(code));
    5968                                answer_error(fd, code);
    6069                                continue REQUEST;
    6170                        }
    6271
    63                         printf("Request for file %.*s\n", (int)name_size, file);
     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);
    6495
    6596                        // Get the fd from the file cache
     
    70101                        // If we can't find the file, return 404
    71102                        if( ans_fd < 0 ) {
    72                                 printf("File Not Found\n");
     103                                printf("=== File Not Found ===\n");
    73104                                answer_error(fd, E404);
    74105                                continue REQUEST;
     
    81112                        sendfile( this.pipe, fd, ans_fd, count);
    82113
    83                         printf("File sent\n");
     114                        if( options.log ) printf("=== Answer sent ===\n");
    84115                }
    85116        }
Note: See TracChangeset for help on using the changeset viewer.