Changeset c3ee5f3


Ignore:
Timestamp:
Jan 8, 2021, 5:20:16 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:
35fd2c4
Parents:
390fb02
Message:

Protocol now returns date in answer header

Location:
benchmark/io/http
Files:
2 edited

Legend:

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

    r390fb02 rc3ee5f3  
    4646}
    4747
     48extern void init_protocol(void);
     49extern void deinit_protocol(void);
     50
    4851//=============================================================================================
    4952// Main
     
    5659        //===================
    5760        // Open Files
    58         printf("Filling cache from %s\n", path);
    59         fill_cache( path );
     61        if (FileExperiment == options.experiment.type) {
     62                printf("Filling cache from %s\n", path);
     63                fill_cache( path );
     64        }
    6065
    6166        //===================
     
    7984                ret = bind( server_fd, (struct sockaddr *)&address, sizeof(address) );
    8085                if(ret < 0) {
    81                         if(errno == 98) {
     86                        if(errno == EADDRINUSE) {
    8287                                if(waited == 0) {
    8388                                        printf("Waiting for port\n");
     
    108113                #endif
    109114                options.clopts.instance = &cl;
     115
     116                init_protocol();
    110117
    111118                int pipe_cnt = options.clopts.nworkers * 2;
     
    162169                }
    163170                free(fds);
     171
     172                deinit_protocol();
    164173        }
    165174
  • benchmark/io/http/protocol.cfa

    r390fb02 rc3ee5f3  
    1818#include "options.hfa"
    1919
    20 const char * volatile date = "Wed, 17 Apr 2013 12:00:00 GMT";
     20const char * volatile date = 0p;
    2121
    2222const char * http_msgs[] = {
     
    7878        for() {
    7979                int ret = cfa_read(fd, (void*)it, count, 0, -1`s, 0p, 0p);
     80                // int ret = read(fd, (void*)it, count);
    8081                if(ret == 0 ) return [OK200, true, 0, 0];
    8182                if(ret < 0 ) {
    8283                        if( errno == EAGAIN || errno == EWOULDBLOCK) continue READ;
     84                        // if( errno == EINVAL ) return [E400, true, 0, 0];
    8385                        abort( "read error: (%d) %s\n", (int)errno, strerror(errno) );
    8486                }
     
    129131        }
    130132}
     133
     134//=============================================================================================
     135
     136#include <clock.hfa>
     137#include <time.hfa>
     138#include <thread.hfa>
     139
     140struct date_buffer {
     141        char buff[100];
     142};
     143
     144thread DateFormater {
     145        int idx;
     146        date_buffer buffers[2];
     147};
     148
     149void ?{}( DateFormater & this ) {
     150        ((thread&)this){ *options.clopts.instance };
     151        this.idx = 0;
     152        memset( this.buffers[0].buff, 0, sizeof(this.buffers[0]) );
     153        memset( this.buffers[1].buff, 0, sizeof(this.buffers[1]) );
     154}
     155
     156void main(DateFormater & this) {
     157        LOOP: for() {
     158                waitfor( ^?{} : this) {
     159                        break LOOP;
     160                }
     161                or else {}
     162
     163                Time now = getTimeNsec();
     164                // Date: Wed, 17 Apr 2013 12:00:00 GMT
     165                strftime( this.buffers[this.idx].buff, 100, "%a, %d %b %Y %H:%M:%S %Z", now );
     166                printf("Changing date to %s\n", this.buffers[this.idx].buff);
     167
     168                char * next = this.buffers[this.idx].buff;
     169                __atomic_exchange_n((char * volatile *)&date, next, __ATOMIC_SEQ_CST);
     170                this.idx = (this.idx + 1) % 2;
     171
     172                sleep(1`s);
     173        }
     174}
     175
     176//=============================================================================================
     177DateFormater * the_date_formatter;
     178
     179void init_protocol(void) {
     180        the_date_formatter = alloc();
     181        (*the_date_formatter){};
     182}
     183
     184void deinit_protocol(void) {
     185        ^(*the_date_formatter){};
     186        free( the_date_formatter );
     187}
Note: See TracChangeset for help on using the changeset viewer.