Changeset d46bdac for benchmark/io/http/worker.cfa
- Timestamp:
- Jan 15, 2021, 3:01:31 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:
- 77ff383
- Parents:
- 2d63023 (diff), b7664a0 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/http/worker.cfa
r2d63023 rd46bdac 6 6 #include <unistd.h> 7 7 8 #include <fstream.hfa> 8 9 #include <iofwd.hfa> 9 10 … … 33 34 CONNECTION: 34 35 for() { 35 if( options.log ) printf("=== Accepting connection ===\n");36 if( options.log ) sout | "=== Accepting connection ==="; 36 37 int fd = cfa_accept4( this.[sockfd, addr, addrlen, flags], 0, -1`s, &this.cancel, 0p ); 37 38 // int fd = accept4( this.[sockfd, addr, addrlen, flags] ); … … 42 43 } 43 44 44 if( options.log ) printf("=== New connection %d, waiting for requests ===\n", fd);45 if( options.log ) sout | "=== New connection" | fd | "" | ", waiting for requests ==="; 45 46 REQUEST: 46 47 for() { … … 53 54 size_t len = options.socket.buflen; 54 55 char buffer[len]; 55 if( options.log ) printf("=== Reading request ===\n");56 if( options.log ) sout | "=== Reading request ==="; 56 57 [code, closed, file, name_size] = http_read(fd, buffer, len, &this.cancel); 57 58 … … 61 62 // If this wasn't a request retrun 400 62 63 if( code != OK200 ) { 63 printf("=== Invalid Request : %d ===\n", code_val(code));64 sout | "=== Invalid Request :" | code_val(code) | "==="; 64 65 answer_error(fd, code); 65 66 continue REQUEST; … … 67 68 68 69 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 ==="; 70 71 71 72 char text[] = "Hello, World!\n"; … … 75 76 if( ret == -ECONNRESET ) break REQUEST; 76 77 77 if( options.log ) printf("=== Answer sent ===\n");78 if( options.log ) sout | "=== Answer sent ==="; 78 79 continue REQUEST; 79 80 } 80 81 81 82 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 ==="; 83 84 84 85 // Send the header … … 86 87 if( ret == -ECONNRESET ) break REQUEST; 87 88 88 if( options.log ) printf("=== Answer sent ===\n");89 if( options.log ) sout | "=== Answer sent ==="; 89 90 continue REQUEST; 90 91 } 91 92 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 } 93 98 94 99 // Get the fd from the file cache … … 99 104 // If we can't find the file, return 404 100 105 if( ans_fd < 0 ) { 101 printf("=== File Not Found ===\n"); 106 sout | "=== File Not Found (" | nonl; 107 write(sout, file, name_size); 108 sout | ") ==="; 102 109 answer_error(fd, E404); 103 110 continue REQUEST; … … 112 119 if( ret == -ECONNRESET ) break REQUEST; 113 120 114 if( options.log ) printf("=== Answer sent ===\n");121 if( options.log ) sout | "=== Answer sent ==="; 115 122 } 116 123 117 if( options.log ) printf("=== Connection closed ===\n");124 if( options.log ) sout | "=== Connection closed ==="; 118 125 close(fd); 119 126 continue CONNECTION;
Note: See TracChangeset
for help on using the changeset viewer.