Ignore:
File:
1 edited

Legend:

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

    ree59ede r8c43d05  
    66#include <unistd.h>
    77
     8#include <fstream.hfa>
    89#include <iofwd.hfa>
    910
     
    3334        CONNECTION:
    3435        for() {
    35                 if( options.log ) printf("=== Accepting connection ===\n");
     36                if( options.log ) sout | "=== Accepting connection ===";
    3637                int fd = cfa_accept4( this.[sockfd, addr, addrlen, flags], 0, -1`s, &this.cancel, 0p );
    3738                // int fd = accept4( this.[sockfd, addr, addrlen, flags] );
     
    4243                }
    4344
    44                 if( options.log ) printf("=== New connection %d, waiting for requests ===\n", fd);
     45                if( options.log ) sout | "=== New connection" | fd | "" | ", waiting for requests ===";
    4546                REQUEST:
    4647                for() {
     
    5354                        size_t len = options.socket.buflen;
    5455                        char buffer[len];
    55                         if( options.log ) printf("=== Reading request ===\n");
     56                        if( options.log ) sout | "=== Reading request ===";
    5657                        [code, closed, file, name_size] = http_read(fd, buffer, len, &this.cancel);
    5758
     
    6162                        // If this wasn't a request retrun 400
    6263                        if( code != OK200 ) {
    63                                 printf("=== Invalid Request : %d ===\n", code_val(code));
     64                                sout | "=== Invalid Request :" | code_val(code) | "===";
    6465                                answer_error(fd, code);
    6566                                continue REQUEST;
     
    6768
    6869                        if(0 == strncmp(file, "plaintext", min(name_size, sizeof("plaintext") ))) {
    69                                 if( options.log ) printf("=== Request for /plaintext ===\n");
     70                                if( options.log ) sout | "=== Request for /plaintext ===";
    7071
    7172                                char text[] = "Hello, World!\n";
     
    7576                                if( ret == -ECONNRESET ) break REQUEST;
    7677
    77                                 if( options.log ) printf("=== Answer sent ===\n");
     78                                if( options.log ) sout | "=== Answer sent ===";
    7879                                continue REQUEST;
    7980                        }
    8081
    8182                        if(0 == strncmp(file, "ping", min(name_size, sizeof("ping") ))) {
    82                                 if( options.log ) printf("=== Request for /ping ===\n");
     83                                if( options.log ) sout | "=== Request for /ping ===";
    8384
    8485                                // Send the header
     
    8687                                if( ret == -ECONNRESET ) break REQUEST;
    8788
    88                                 if( options.log ) printf("=== Answer sent ===\n");
     89                                if( options.log ) sout | "=== Answer sent ===";
    8990                                continue REQUEST;
    9091                        }
    9192
    92                         if( options.log ) printf("=== Request for file %.*s ===\n", (int)name_size, file);
     93                        if( options.log ) {
     94                                sout | "=== Request for file " | nonl;
     95                                write(sout, file, name_size);
     96                                sout | " ===";
     97                        }
    9398
    9499                        // Get the fd from the file cache
     
    99104                        // If we can't find the file, return 404
    100105                        if( ans_fd < 0 ) {
    101                                 printf("=== File Not Found ===\n");
     106                                sout | "=== File Not Found (" | nonl;
     107                                write(sout, file, name_size);
     108                                sout | ") ===";
    102109                                answer_error(fd, E404);
    103110                                continue REQUEST;
     
    112119                        if( ret == -ECONNRESET ) break REQUEST;
    113120
    114                         if( options.log ) printf("=== Answer sent ===\n");
     121                        if( options.log ) sout | "=== Answer sent ===";
    115122                }
    116123
    117                 if( options.log ) printf("=== Connection closed ===\n");
     124                if( options.log ) sout | "=== Connection closed ===";
    118125                close(fd);
    119126                continue CONNECTION;
Note: See TracChangeset for help on using the changeset viewer.