Ignore:
File:
1 edited

Legend:

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

    rd9c2284 rc82af9f  
    1212#include "filecache.hfa"
    1313
     14extern "C" {
     15// extern ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count);
     16extern 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
     19ssize_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
    1424//=============================================================================================
    1525// Worker Thread
    1626//=============================================================================================
    1727void ?{}( Worker & this ) {
    18         ((thread&)this){ "Server Worker Thread", *options.clopts.instance };
    19         this.pipe[0] = -1;
    20         this.pipe[1] = -1;
     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) ); }
    2131}
    2232
    2333void main( Worker & this ) {
    24         park( __cfaabi_dbg_ctx );
    25         /* paranoid */ assert( this.pipe[0] != -1 );
    26         /* paranoid */ assert( this.pipe[1] != -1 );
    27 
    2834        CONNECTION:
    29         for() {
    30                 int fd = take(wait_connect);
    31                 if (fd < 0) break;
    32 
    33                 printf("New connection %d, waiting for requests\n", fd);
     35        while( int fd = take(wait_connect); fd >= 0) {
     36            printf("New connection, waiting for requests\n");
    3437                REQUEST:
    3538                for() {
     
    4043
    4144                        // Read the http request
    42                         size_t len = options.socket.buflen;
     45                        size_t len = 1024;
    4346                        char buffer[len];
    4447                        printf("Reading request\n");
     
    5356                        // If this wasn't a request retrun 400
    5457                        if( code != OK200 ) {
    55                                 printf("Invalid Request : %d\n", code_val(code));
     58                                printf("Invalid Request\n");
    5659                                answer_error(fd, code);
    5760                                continue REQUEST;
    5861                        }
    5962
    60                         printf("Request for file %.*s\n", (int)name_size, file);
     63                        printf("Request for file %.*s\n", name_size, file);
    6164
    6265                        // Get the fd from the file cache
     
    8790//=============================================================================================
    8891void ?{}( Acceptor & this, int sockfd, struct sockaddr * addr, socklen_t * addrlen, int flags ) {
    89         ((thread&)this){ "Acceptor Thread", *options.clopts.instance };
     92        ((thread&)this){ "Acceptor Thread", *options.the_cluster };
    9093        this.sockfd  = sockfd;
    9194        this.addr    = addr;
     
    102105                }
    103106
    104                 printf("New connection accepted\n");
     107            printf("New connection accepted\n");
    105108                put( wait_connect, ret );
    106         }
     109      }
    107110}
Note: See TracChangeset for help on using the changeset viewer.