Changeset d95969a for benchmark/io/http/main.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/main.cfa (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/http/main.cfa
rb6a8b31 rd95969a 6 6 #include <unistd.h> 7 7 extern "C" { 8 #include <signal.h> 8 9 #include <sys/socket.h> 9 10 #include <netinet/in.h> 10 11 } 11 12 13 #include <fstream.hfa> 12 14 #include <kernel.hfa> 15 #include <iofwd.hfa> 13 16 #include <stats.hfa> 14 17 #include <time.hfa> … … 50 53 51 54 //============================================================================================= 55 // Stats Printer 56 //=============================================================================================' 57 58 thread StatsPrinter {}; 59 60 void ?{}( StatsPrinter & this ) { 61 ((thread&)this){ "Stats Printer Thread" }; 62 } 63 64 void main(StatsPrinter & this) { 65 LOOP: for() { 66 waitfor( ^?{} : this) { 67 break LOOP; 68 } 69 or else {} 70 71 sleep(10`s); 72 73 print_stats_now( *options.clopts.instance, CFA_STATS_READY_Q | CFA_STATS_IO ); 74 } 75 } 76 77 //============================================================================================= 52 78 // Main 53 79 //=============================================================================================' 54 80 int main( int argc, char * argv[] ) { 81 __sighandler_t s = 1p; 82 signal(SIGPIPE, s); 83 55 84 //=================== 56 85 // Parse args 57 const char * path =parse_options(argc, argv);86 parse_options(argc, argv); 58 87 59 88 //=================== 60 89 // Open Files 61 printf("Filling cache from %s\n", path); 62 fill_cache( path ); 90 if( options.file_cache.path ) { 91 sout | "Filling cache from" | options.file_cache.path; 92 fill_cache( options.file_cache.path ); 93 } 63 94 64 95 //=================== 65 96 // Open Socket 66 printf("%ld : Listening on port %d\n", getpid(), options.socket.port);97 sout | getpid() | ": Listening on port" | options.socket.port; 67 98 int server_fd = socket(AF_INET, SOCK_STREAM, 0); 68 99 if(server_fd < 0) { … … 84 115 if(errno == EADDRINUSE) { 85 116 if(waited == 0) { 86 printf("Waiting for port\n");117 sout | "Waiting for port"; 87 118 } else { 88 printf("\r%d", waited);89 f flush(stdout);119 sout | "\r" | waited | nonl; 120 flush( sout ); 90 121 } 91 122 waited ++; … … 122 153 } 123 154 124 if(options.file_cache. fixed_fds) {155 if(options.file_cache.path && options.file_cache.fixed_fds) { 125 156 register_fixed_files(cl, fds, pipe_off); 126 157 } … … 128 159 { 129 160 ServerProc procs[options.clopts.nprocs]; 161 StatsPrinter printer; 130 162 131 163 init_protocol(); … … 148 180 unpark( workers[i] ); 149 181 } 150 printf("%d workers started on %d processors\n", options.clopts.nworkers, options.clopts.nprocs);182 sout | options.clopts.nworkers | "workers started on" | options.clopts.nprocs | "processors"; 151 183 { 152 184 char buffer[128]; 153 while( !feof(stdin)) {154 fgets(buffer, 128, stdin);185 while(int ret = cfa_read(0, buffer, 128, 0, -1`s, 0p, 0p); ret != 0) { 186 if(ret < 0) abort( "main read error: (%d) %s\n", (int)errno, strerror(errno) ); 155 187 } 156 188 157 printf("Shutting Down\n"); 158 } 159 189 sout | "Shutdown received"; 190 } 191 192 sout | "Notifying connections..." | nonl; flush( sout ); 160 193 for(i; options.clopts.nworkers) { 161 printf("Cancelling %p\n", (void*)workers[i].cancel.target);162 194 workers[i].done = true; 163 195 cancel(workers[i].cancel); 164 196 } 165 166 printf("Shutting down socket\n"); 197 sout | "done"; 198 199 sout | "Shutting down socket..." | nonl; flush( sout ); 167 200 int ret = shutdown( server_fd, SHUT_RD ); 168 if( ret < 0 ) { abort( "shutdown error: (%d) %s\n", (int)errno, strerror(errno) ); } 201 if( ret < 0 ) { 202 abort( "shutdown error: (%d) %s\n", (int)errno, strerror(errno) ); 203 } 204 sout | "done"; 169 205 170 206 //=================== 171 207 // Close Socket 172 printf("Closing Socket\n");208 sout | "Closing Socket..." | nonl; flush( sout ); 173 209 ret = close( server_fd ); 174 210 if(ret < 0) { 175 211 abort( "close socket error: (%d) %s\n", (int)errno, strerror(errno) ); 176 212 } 213 sout | "done"; 214 215 sout | "Stopping connection threads..." | nonl; flush( sout ); 177 216 } 178 printf("Workers Closed\n"); 179 217 sout | "done"; 218 219 sout | "Stopping protocol threads..." | nonl; flush( sout ); 180 220 deinit_protocol(); 181 } 182 221 sout | "done"; 222 223 sout | "Stopping processors..." | nonl; flush( sout ); 224 } 225 sout | "done"; 226 227 sout | "Closing splice fds..." | nonl; flush( sout ); 183 228 for(i; pipe_cnt) { 184 229 ret = close( fds[pipe_off + i] ); … … 188 233 } 189 234 free(fds); 190 191 } 235 sout | "done"; 236 237 sout | "Stopping processors..." | nonl; flush( sout ); 238 } 239 sout | "done"; 192 240 193 241 //=================== 194 242 // Close Files 195 printf("Closing Files\n"); 196 close_cache(); 197 } 243 if( options.file_cache.path ) { 244 sout | "Closing open files..." | nonl; flush( sout ); 245 close_cache(); 246 sout | "done"; 247 } 248 }
Note:
See TracChangeset
for help on using the changeset viewer.