Changeset 481ee28
- Timestamp:
- Jan 12, 2021, 1:12:24 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 7dafb7b
- Parents:
- 35285fd
- Location:
- benchmark/io/http
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/http/main.cfa
r35285fd r481ee28 59 59 //=================== 60 60 // Open Files 61 if (FileExperiment == options.experiment.type) { 62 printf("Filling cache from %s\n", path); 63 fill_cache( path ); 64 } 61 printf("Filling cache from %s\n", path); 62 fill_cache( path ); 65 63 66 64 //=================== … … 162 160 for(i; options.clopts.nworkers) { 163 161 printf("Cancelling %p\n", (void*)workers[i].cancel.target); 162 workers[i].done = true; 164 163 cancel(workers[i].cancel); 165 164 } -
benchmark/io/http/options.cfa
r35285fd r481ee28 15 15 16 16 Options options @= { 17 { // experiment 18 FileExperiment, // type 19 }, 17 false, // log 20 18 21 19 { // file_cache … … 43 41 }; 44 42 45 static bool parse(const char * arg, ExprimentType & value) {46 if(strcmp(arg, "file") == 0) {47 value = FileExperiment;48 return true;49 }50 51 if(strcmp(arg, "plaintext") == 0) {52 value = HelloWorldExperiment;53 return true;54 }55 56 return false;57 }58 59 43 const char * parse_options( int argc, char * argv[] ) { 60 44 bool subthrd = false; … … 68 52 {'p', "port", "Port the server will listen on", options.socket.port}, 69 53 {'c', "cpus", "Number of processors to use", options.clopts.nprocs}, 70 {' T', "experiment", "Experiment type to run: file, plaintext", options.experiment.type},54 {'L', "log", "Enable logs", options.log, parse_settrue}, 71 55 {'t', "threads", "Number of worker threads to use", options.clopts.nworkers}, 72 56 {'b', "accept-backlog", "Maximum number of pending accepts", options.socket.backlog}, -
benchmark/io/http/options.hfa
r35285fd r481ee28 7 7 struct cluster; 8 8 9 enum ExprimentType {10 FileExperiment,11 HelloWorldExperiment12 };13 14 9 struct Options { 15 struct { 16 ExprimentType type; 17 } experiment; 10 bool log; 18 11 19 12 struct { -
benchmark/io/http/protocol.cfa
r35285fd r481ee28 103 103 } 104 104 105 printf("%.*s\n", rlen, buffer);105 if( options.log ) printf("%.*s\n", rlen, buffer); 106 106 107 107 it = buffer; -
benchmark/io/http/worker.cfa
r35285fd r481ee28 19 19 this.pipe[0] = -1; 20 20 this.pipe[1] = -1; 21 this.done = false; 22 } 23 24 extern "C" { 25 extern int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags); 21 26 } 22 27 … … 28 33 CONNECTION: 29 34 for() { 30 printf("=== Accepting connection ===\n");35 if( options.log ) printf("=== Accepting connection ===\n"); 31 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] ); 32 38 if(fd < 0) { 33 39 if( errno == ECONNABORTED ) break; 34 if( errno == EINVAL ) break;40 if( errno == EINVAL && this.done ) break; 35 41 abort( "accept error: (%d) %s\n", (int)errno, strerror(errno) ); 36 42 } 37 43 38 printf("=== New connection %d, waiting for requests ===\n", fd);44 if( options.log ) printf("=== New connection %d, waiting for requests ===\n", fd); 39 45 REQUEST: 40 46 for() { … … 47 53 size_t len = options.socket.buflen; 48 54 char buffer[len]; 49 printf("=== Reading request ===\n");55 if( options.log ) printf("=== Reading request ===\n"); 50 56 [code, closed, file, name_size] = http_read(fd, buffer, len, &this.cancel); 51 57 52 58 // if we are done, break out of the loop 53 59 if( closed ) { 54 printf("=== Connection closed ===\n");60 if( options.log ) printf("=== Connection closed ===\n"); 55 61 continue CONNECTION; 56 62 } … … 58 64 // If this wasn't a request retrun 400 59 65 if( code != OK200 ) { 60 printf("=== Invalid Request : %d ===\n", code_val(code));66 if( options.log ) printf("=== Invalid Request : %d ===\n", code_val(code)); 61 67 answer_error(fd, code); 62 68 continue REQUEST; … … 64 70 65 71 if(0 == strncmp(file, "plaintext", min(name_size, sizeof("plaintext") ))) { 66 printf("=== Request for /plaintext ===\n");72 if( options.log ) printf("=== Request for /plaintext ===\n"); 67 73 68 74 char text[] = "Hello, World!\n"; … … 72 78 } 73 79 else { 74 printf("=== Request for file %.*s ===\n", (int)name_size, file);80 if( options.log ) printf("=== Request for file %.*s ===\n", (int)name_size, file); 75 81 76 82 // Get the fd from the file cache … … 81 87 // If we can't find the file, return 404 82 88 if( ans_fd < 0 ) { 83 printf("=== File Not Found ===\n");89 if( options.log ) printf("=== File Not Found ===\n"); 84 90 answer_error(fd, E404); 85 91 continue REQUEST; … … 93 99 } 94 100 95 printf("=== Answer sent ===\n");101 if( options.log ) printf("=== Answer sent ===\n"); 96 102 } 97 103 } -
benchmark/io/http/worker.hfa
r35285fd r481ee28 18 18 int flags; 19 19 io_cancellation cancel; 20 volatile bool done; 20 21 }; 21 22 void ?{}( Worker & this);
Note: See TracChangeset
for help on using the changeset viewer.