Changeset d95969a for benchmark/io/http/worker.cfa
- Timestamp:
- Jan 25, 2021, 3:45:42 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- c292244
- Parents:
- b6a8b31 (diff), 7158202 (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
-
benchmark/io/http/worker.cfa (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/http/worker.cfa
rb6a8b31 rd95969a 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] ); 38 39 if(fd < 0) { 39 40 if( errno == ECONNABORTED ) break; 40 if( errno == EINVAL && this.done) break;41 if( this.done && (errno == EINVAL || errno == EBADF) ) break; 41 42 abort( "accept error: (%d) %s\n", (int)errno, strerror(errno) ); 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 58 59 // if we are done, break out of the loop 59 if( closed ) { 60 if( options.log ) printf("=== Connection closed ===\n"); 61 close(fd); 62 continue CONNECTION; 63 } 60 if( closed ) break REQUEST; 64 61 65 62 // If this wasn't a request retrun 400 66 63 if( code != OK200 ) { 67 printf("=== Invalid Request : %d ===\n", code_val(code));64 sout | "=== Invalid Request :" | code_val(code) | "==="; 68 65 answer_error(fd, code); 69 66 continue REQUEST; … … 71 68 72 69 if(0 == strncmp(file, "plaintext", min(name_size, sizeof("plaintext") ))) { 73 if( options.log ) printf("=== Request for /plaintext ===\n");70 if( options.log ) sout | "=== Request for /plaintext ==="; 74 71 75 72 char text[] = "Hello, World!\n"; 76 73 77 74 // Send the header 78 answer_plain(fd, text, sizeof(text)); 75 int ret = answer_plain(fd, text, sizeof(text)); 76 if( ret == -ECONNRESET ) break REQUEST; 79 77 80 if( options.log ) printf("=== Answer sent ===\n");78 if( options.log ) sout | "=== Answer sent ==="; 81 79 continue REQUEST; 82 80 } 83 81 84 82 if(0 == strncmp(file, "ping", min(name_size, sizeof("ping") ))) { 85 if( options.log ) printf("=== Request for /ping ===\n");83 if( options.log ) sout | "=== Request for /ping ==="; 86 84 87 85 // Send the header 88 answer_empty(fd); 86 int ret = answer_empty(fd); 87 if( ret == -ECONNRESET ) break REQUEST; 89 88 90 if( options.log ) printf("=== Answer sent ===\n");89 if( options.log ) sout | "=== Answer sent ==="; 91 90 continue REQUEST; 92 91 } 93 92 94 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 } 98 99 if( !options.file_cache.path ) { 100 if( options.log ) { 101 sout | "=== File Not Found (" | nonl; 102 write(sout, file, name_size); 103 sout | ") ==="; 104 } 105 answer_error(fd, E405); 106 continue REQUEST; 107 } 95 108 96 109 // Get the fd from the file cache … … 101 114 // If we can't find the file, return 404 102 115 if( ans_fd < 0 ) { 103 printf("=== File Not Found ===\n"); 116 if( options.log ) { 117 sout | "=== File Not Found (" | nonl; 118 write(sout, file, name_size); 119 sout | ") ==="; 120 } 104 121 answer_error(fd, E404); 105 122 continue REQUEST; … … 107 124 108 125 // Send the header 109 answer_header(fd, count); 126 int ret = answer_header(fd, count); 127 if( ret == -ECONNRESET ) break REQUEST; 110 128 111 129 // Send the desired file 112 sendfile( this.pipe, fd, ans_fd, count); 130 ret = sendfile( this.pipe, fd, ans_fd, count); 131 if( ret == -ECONNRESET ) break REQUEST; 113 132 114 if( options.log ) printf("=== Answer sent ===\n");133 if( options.log ) sout | "=== Answer sent ==="; 115 134 } 135 136 if( options.log ) sout | "=== Connection closed ==="; 137 close(fd); 138 continue CONNECTION; 116 139 } 117 140 }
Note:
See TracChangeset
for help on using the changeset viewer.