Ignore:
Timestamp:
Jul 23, 2020, 3:37:05 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
f4ec4a90
Parents:
f0c3120 (diff), e262b5e (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

    rf0c3120 r04b73b6  
    1212#include "filecache.hfa"
    1313
    14 extern "C" {
    15 // extern ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count);
    16 extern ssize_t splice(int fd_in, loff_t *off_in, int fd_out, loff_t *off_out, size_t len, unsigned int flags);
    17 }
    18 
    19 ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count) {
    20         return splice(in_fd, offset, out_fd, 0p, count, 0);
    21 }
    22 
    23 
    2414//=============================================================================================
    2515// Worker Thread
    2616//=============================================================================================
    2717void ?{}( Worker & this ) {
    28         ((thread&)this){ "Server Worker Thread", *options.the_cluster };
    29         int ret = pipe(this.pipe);
    30         if( ret < 0 ) { abort( "pipe error: (%d) %s\n", (int)errno, strerror(errno) ); }
     18        ((thread&)this){ "Server Worker Thread", *options.clopts.instance };
     19        this.pipe[0] = -1;
     20        this.pipe[1] = -1;
    3121}
    3222
    3323void main( Worker & this ) {
     24        park( __cfaabi_dbg_ctx );
     25        /* paranoid */ assert( this.pipe[0] != -1 );
     26        /* paranoid */ assert( this.pipe[1] != -1 );
     27
    3428        CONNECTION:
    35         while( int fd = take(wait_connect); fd >= 0) {
    36             printf("New connection, waiting for requests\n");
     29        for() {
     30                int fd = take(wait_connect);
     31                if (fd < 0) break;
     32
     33                printf("New connection %d, waiting for requests\n", fd);
    3734                REQUEST:
    3835                for() {
     
    4340
    4441                        // Read the http request
    45                         size_t len = 1024;
     42                        size_t len = options.socket.buflen;
    4643                        char buffer[len];
    4744                        printf("Reading request\n");
     
    5653                        // If this wasn't a request retrun 400
    5754                        if( code != OK200 ) {
    58                                 printf("Invalid Request\n");
     55                                printf("Invalid Request : %d\n", code_val(code));
    5956                                answer_error(fd, code);
    6057                                continue REQUEST;
    6158                        }
    6259
    63                         printf("Request for file %.*s\n", name_size, file);
     60                        printf("Request for file %.*s\n", (int)name_size, file);
    6461
    6562                        // Get the fd from the file cache
     
    9087//=============================================================================================
    9188void ?{}( Acceptor & this, int sockfd, struct sockaddr * addr, socklen_t * addrlen, int flags ) {
    92         ((thread&)this){ "Acceptor Thread", *options.the_cluster };
     89        ((thread&)this){ "Acceptor Thread", *options.clopts.instance };
    9390        this.sockfd  = sockfd;
    9491        this.addr    = addr;
     
    105102                }
    106103
    107             printf("New connection accepted\n");
     104                printf("New connection accepted\n");
    108105                put( wait_connect, ret );
    109       }
     106        }
    110107}
Note: See TracChangeset for help on using the changeset viewer.