Changeset 481ee28 for benchmark/io/http/worker.cfa
- Timestamp:
- Jan 12, 2021, 1:12:24 PM (3 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 7dafb7b
- Parents:
- 35285fd
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/http/worker.cfa
r35285fd r481ee28 19 19 this.pipe[0] = -1; 20 20 this.pipe[1] = -1; 21 this.done = false; 22 } 23 24 extern "C" { 25 extern int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags); 21 26 } 22 27 … … 28 33 CONNECTION: 29 34 for() { 30 printf("=== Accepting connection ===\n");35 if( options.log ) printf("=== Accepting connection ===\n"); 31 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] ); 32 38 if(fd < 0) { 33 39 if( errno == ECONNABORTED ) break; 34 if( errno == EINVAL ) break;40 if( errno == EINVAL && this.done ) break; 35 41 abort( "accept error: (%d) %s\n", (int)errno, strerror(errno) ); 36 42 } 37 43 38 printf("=== New connection %d, waiting for requests ===\n", fd);44 if( options.log ) printf("=== New connection %d, waiting for requests ===\n", fd); 39 45 REQUEST: 40 46 for() { … … 47 53 size_t len = options.socket.buflen; 48 54 char buffer[len]; 49 printf("=== Reading request ===\n");55 if( options.log ) printf("=== Reading request ===\n"); 50 56 [code, closed, file, name_size] = http_read(fd, buffer, len, &this.cancel); 51 57 52 58 // if we are done, break out of the loop 53 59 if( closed ) { 54 printf("=== Connection closed ===\n");60 if( options.log ) printf("=== Connection closed ===\n"); 55 61 continue CONNECTION; 56 62 } … … 58 64 // If this wasn't a request retrun 400 59 65 if( code != OK200 ) { 60 printf("=== Invalid Request : %d ===\n", code_val(code));66 if( options.log ) printf("=== Invalid Request : %d ===\n", code_val(code)); 61 67 answer_error(fd, code); 62 68 continue REQUEST; … … 64 70 65 71 if(0 == strncmp(file, "plaintext", min(name_size, sizeof("plaintext") ))) { 66 printf("=== Request for /plaintext ===\n");72 if( options.log ) printf("=== Request for /plaintext ===\n"); 67 73 68 74 char text[] = "Hello, World!\n"; … … 72 78 } 73 79 else { 74 printf("=== Request for file %.*s ===\n", (int)name_size, file);80 if( options.log ) printf("=== Request for file %.*s ===\n", (int)name_size, file); 75 81 76 82 // Get the fd from the file cache … … 81 87 // If we can't find the file, return 404 82 88 if( ans_fd < 0 ) { 83 printf("=== File Not Found ===\n");89 if( options.log ) printf("=== File Not Found ===\n"); 84 90 answer_error(fd, E404); 85 91 continue REQUEST; … … 93 99 } 94 100 95 printf("=== Answer sent ===\n");101 if( options.log ) printf("=== Answer sent ===\n"); 96 102 } 97 103 }
Note: See TracChangeset
for help on using the changeset viewer.