Changeset c4b10e2 for benchmark/io/http/main.cfa
- Timestamp:
- Jun 4, 2022, 1:12:56 PM (2 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- ce98816
- Parents:
- 153570d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/http/main.cfa
r153570d rc4b10e2 23 23 #include "filecache.hfa" 24 24 #include "options.hfa" 25 #include "socket.hfa" 25 26 #include "worker.hfa" 26 27 … … 195 196 //=============================================================================================' 196 197 int main( int argc, char * argv[] ) { 198 int ret; 197 199 __sighandler_t s = 1p; 198 200 signal(SIGPIPE, s); … … 226 228 // Open Socket 227 229 sout | getpid() | ": Listening on port" | options.socket.port; 228 int server_fd = socket(AF_INET, SOCK_STREAM, 0); 229 if(server_fd < 0) { 230 abort( "socket error: (%d) %s\n", (int)errno, strerror(errno) ); 231 } 232 233 int ret = 0; 230 234 231 struct sockaddr_in address; 235 int addrlen = sizeof(address); 236 memset( (char *)&address, '\0' ); 237 address.sin_family = AF_INET; 238 address.sin_addr.s_addr = htonl(INADDR_ANY); 239 address.sin_port = htons( options.socket.port ); 240 241 int waited = 0; 242 for() { 243 int sockfd = server_fd; 244 __CONST_SOCKADDR_ARG addr; 245 addr.__sockaddr__ = (struct sockaddr *)&address; 246 socklen_t addrlen = sizeof(address); 247 ret = bind( sockfd, addr, addrlen ); 248 if(ret < 0) { 249 if(errno == EADDRINUSE) { 250 if(waited == 0) { 251 if(!options.interactive) abort | "Port already in use in non-interactive mode. Aborting"; 252 sout | "Waiting for port"; 253 } else { 254 sout | "\r" | waited | nonl; 255 flush( sout ); 256 } 257 waited ++; 258 sleep( 1`s ); 259 continue; 260 } 261 abort( "bind error: (%d) %s\n", (int)errno, strerror(errno) ); 262 } 263 break; 264 } 265 266 ret = listen( server_fd, options.socket.backlog ); 267 if(ret < 0) { 268 abort( "listen error: (%d) %s\n", (int)errno, strerror(errno) ); 269 } 232 int addrlen = prepaddr(address); 233 234 int server_fd = listener(address, addrlen); 270 235 271 236 //=================== … … 361 326 sout | "Stopping connection threads..." | nonl; flush( sout ); 362 327 for(i; options.clopts.nworkers) { 328 for(j; 2) { 329 ret = close(workers[i].pipe[j]); 330 if(ret < 0) abort( "close pipe %d error: (%d) %s\n", j, (int)errno, strerror(errno) ); 331 } 363 332 join(workers[i]); 364 333 } … … 384 353 sout | "done"; 385 354 386 sout | "Closing splice fds..." | nonl; flush( sout );387 for(i; pipe_cnt) {388 ret = close( fds[pipe_off + i] );389 if(ret < 0) {390 abort( "close pipe error: (%d) %s\n", (int)errno, strerror(errno) );391 }392 }355 // sout | "Closing splice fds..." | nonl; flush( sout ); 356 // for(i; pipe_cnt) { 357 // ret = close( fds[pipe_off + i] ); 358 // if(ret < 0) { 359 // abort( "close pipe error: (%d) %s\n", (int)errno, strerror(errno) ); 360 // } 361 // } 393 362 free(fds); 394 363 sout | "done";
Note: See TracChangeset
for help on using the changeset viewer.