- Timestamp:
- Jun 3, 2022, 6:54:31 PM (2 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- c4b10e2
- Parents:
- 7affcda
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/http/main.cfa
r7affcda r153570d 2 2 3 3 #include <errno.h> 4 #include <signal.h> 4 5 #include <stdio.h> 5 6 #include <string.h> … … 8 9 #include <sched.h> 9 10 #include <signal.h> 11 #include <sys/eventfd.h> 10 12 #include <sys/socket.h> 11 13 #include <netinet/in.h> … … 177 179 178 180 //============================================================================================= 181 // Termination 182 //============================================================================================= 183 184 int closefd; 185 void cleanstop(int) { 186 eventfd_t buffer = 1; 187 char * buffer_s = (char*)&buffer; 188 int ret = write(closefd, buffer_s, sizeof(buffer)); 189 if(ret < 0) abort( "eventfd write error: (%d) %s\n", (int)errno, strerror(errno) ); 190 return; 191 } 192 193 //============================================================================================= 179 194 // Main 180 195 //=============================================================================================' … … 186 201 // Parse args 187 202 parse_options(argc, argv); 203 204 //=================== 205 // Setup non-interactive termination 206 if(!options.interactive) { 207 closefd = eventfd(0, 0); 208 if(closefd < 0) abort( "eventfd error: (%d) %s\n", (int)errno, strerror(errno) ); 209 210 sighandler_t prev = signal(SIGTERM, cleanstop); 211 intptr_t prev_workaround = (intptr_t) prev; 212 // can't use SIG_ERR it crashes the compiler 213 if(prev_workaround == -1) abort( "signal setup error: (%d) %s\n", (int)errno, strerror(errno) ); 214 215 sout | "Signal termination ready"; 216 } 188 217 189 218 //=================== … … 257 286 258 287 { 288 // Stats printer makes a copy so this needs to persist longer than normal 289 Worker * workers; 259 290 ServerCluster cl[options.clopts.nclusters]; 260 291 261 292 init_protocol(); 262 293 { 263 Worker *workers = anew(options.clopts.nworkers);294 workers = anew(options.clopts.nworkers); 264 295 cl[0].prnt->workers = workers; 265 296 cl[0].prnt->worker_cnt = options.clopts.nworkers; … … 285 316 } 286 317 sout | nl; 287 if(!options.interactive) park();288 318 { 289 char buffer[128]; 290 for() { 291 int ret = cfa_read(0, buffer, 128, 0); 292 if(ret == 0) break; 319 if(options.interactive) { 320 char buffer[128]; 321 for() { 322 int ret = cfa_read(0, buffer, 128, 0); 323 if(ret == 0) break; 324 if(ret < 0) abort( "main read error: (%d) %s\n", (int)errno, strerror(errno) ); 325 sout | "User wrote '" | "" | nonl; 326 write(sout, buffer, ret - 1); 327 sout | "'"; 328 } 329 } 330 else { 331 char buffer[sizeof(eventfd_t)]; 332 int ret = cfa_read(closefd, buffer, sizeof(eventfd_t), 0); 293 333 if(ret < 0) abort( "main read error: (%d) %s\n", (int)errno, strerror(errno) ); 294 sout | "User wrote '" | "" | nonl;295 write(sout, buffer, ret - 1);296 sout | "'";297 334 } 298 335 … … 323 360 324 361 sout | "Stopping connection threads..." | nonl; flush( sout ); 325 adelete(workers); 362 for(i; options.clopts.nworkers) { 363 join(workers[i]); 364 } 326 365 } 327 366 sout | "done"; … … 330 369 deinit_protocol(); 331 370 sout | "done"; 371 372 sout | "Stopping printer threads..." | nonl; flush( sout ); 373 for(i; options.clopts.nclusters) { 374 StatsPrinter * p = cl[i].prnt; 375 if(p) join(*p); 376 } 377 sout | "done"; 378 379 // Now that the stats printer is stopped, we can reclaim this 380 adelete(workers); 332 381 333 382 sout | "Stopping processors/clusters..." | nonl; flush( sout );
Note: See TracChangeset
for help on using the changeset viewer.