Changeset 8e4aa05 for benchmark/io/http/worker.cfa
- Timestamp:
- Mar 4, 2021, 7:40:25 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:
- 77d601f
- Parents:
- 342af53 (diff), a5040fe (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
r342af53 r8e4aa05 6 6 #include <unistd.h> 7 7 8 #include <fstream.hfa> 8 9 #include <iofwd.hfa> 9 10 … … 16 17 //============================================================================================= 17 18 void ?{}( Worker & this ) { 18 ((thread&)this){ "Server Worker Thread", *options.clopts.instance }; 19 size_t cli = rand() % options.clopts.cltr_cnt; 20 ((thread&)this){ "Server Worker Thread", *options.clopts.instance[cli] }; 21 options.clopts.thrd_cnt[cli]++; 19 22 this.pipe[0] = -1; 20 23 this.pipe[1] = -1; … … 33 36 CONNECTION: 34 37 for() { 35 if( options.log ) printf("=== Accepting connection ===\n"); 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] ); 38 if( options.log ) sout | "=== Accepting connection ==="; 39 int fd = cfa_accept4( this.[sockfd, addr, addrlen, flags], CFA_IO_LAZY ); 38 40 if(fd < 0) { 39 41 if( errno == ECONNABORTED ) break; 40 if( errno == EINVAL && this.done) break;42 if( this.done && (errno == EINVAL || errno == EBADF) ) break; 41 43 abort( "accept error: (%d) %s\n", (int)errno, strerror(errno) ); 42 44 } 45 if(this.done) break; 43 46 44 if( options.log ) printf("=== New connection %d, waiting for requests ===\n", fd);47 if( options.log ) sout | "=== New connection" | fd | "" | ", waiting for requests ==="; 45 48 REQUEST: 46 49 for() { … … 53 56 size_t len = options.socket.buflen; 54 57 char buffer[len]; 55 if( options.log ) printf("=== Reading request ===\n");56 [code, closed, file, name_size] = http_read(fd, buffer, len , &this.cancel);58 if( options.log ) sout | "=== Reading request ==="; 59 [code, closed, file, name_size] = http_read(fd, buffer, len); 57 60 58 61 // 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 } 62 if( closed ) break REQUEST; 64 63 65 64 // If this wasn't a request retrun 400 66 65 if( code != OK200 ) { 67 printf("=== Invalid Request : %d ===\n", code_val(code));66 sout | "=== Invalid Request :" | code_val(code) | "==="; 68 67 answer_error(fd, code); 69 68 continue REQUEST; … … 71 70 72 71 if(0 == strncmp(file, "plaintext", min(name_size, sizeof("plaintext") ))) { 73 if( options.log ) printf("=== Request for /plaintext ===\n");72 if( options.log ) sout | "=== Request for /plaintext ==="; 74 73 75 char text[] = "Hello, World!\n"; 74 int ret = answer_plaintext(fd); 75 if( ret == -ECONNRESET ) break REQUEST; 76 76 77 // Send the header 78 answer_plain(fd, text, sizeof(text)); 79 80 if( options.log ) printf("=== Answer sent ===\n"); 77 if( options.log ) sout | "=== Answer sent ==="; 81 78 continue REQUEST; 82 79 } 83 80 84 81 if(0 == strncmp(file, "ping", min(name_size, sizeof("ping") ))) { 85 if( options.log ) printf("=== Request for /ping ===\n");82 if( options.log ) sout | "=== Request for /ping ==="; 86 83 87 84 // Send the header 88 answer_empty(fd); 85 int ret = answer_empty(fd); 86 if( ret == -ECONNRESET ) break REQUEST; 89 87 90 if( options.log ) printf("=== Answer sent ===\n");88 if( options.log ) sout | "=== Answer sent ==="; 91 89 continue REQUEST; 92 90 } 93 91 94 if( options.log ) printf("=== Request for file %.*s ===\n", (int)name_size, file); 92 if( options.log ) { 93 sout | "=== Request for file " | nonl; 94 write(sout, file, name_size); 95 sout | " ==="; 96 } 97 98 if( !options.file_cache.path ) { 99 if( options.log ) { 100 sout | "=== File Not Found (" | nonl; 101 write(sout, file, name_size); 102 sout | ") ==="; 103 } 104 answer_error(fd, E405); 105 continue REQUEST; 106 } 95 107 96 108 // Get the fd from the file cache … … 101 113 // If we can't find the file, return 404 102 114 if( ans_fd < 0 ) { 103 printf("=== File Not Found ===\n"); 115 if( options.log ) { 116 sout | "=== File Not Found (" | nonl; 117 write(sout, file, name_size); 118 sout | ") ==="; 119 } 104 120 answer_error(fd, E404); 105 121 continue REQUEST; … … 107 123 108 124 // Send the header 109 answer_header(fd, count); 125 int ret = answer_header(fd, count); 126 if( ret == -ECONNRESET ) break REQUEST; 110 127 111 128 // Send the desired file 112 sendfile( this.pipe, fd, ans_fd, count); 129 ret = sendfile( this.pipe, fd, ans_fd, count); 130 if( ret == -ECONNRESET ) break REQUEST; 113 131 114 if( options.log ) printf("=== Answer sent ===\n");132 if( options.log ) sout | "=== Answer sent ==="; 115 133 } 134 135 if( options.log ) sout | "=== Connection closed ==="; 136 close(fd); 137 continue CONNECTION; 116 138 } 117 139 }
Note:
See TracChangeset
for help on using the changeset viewer.