Changeset 402658b1 for benchmark/io/http/worker.cfa
- Timestamp:
- Jan 13, 2021, 10:23:07 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 9153e53
- Parents:
- bace538 (diff), a00bc5b (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
rbace538 r402658b1 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 int fd = cfa_accept4( this.[sockfd, addr, addrlen, flags], 0, -1`s, 0p, 0p ); 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] ); 31 38 if(fd < 0) { 32 39 if( errno == ECONNABORTED ) break; 40 if( errno == EINVAL && this.done ) break; 33 41 abort( "accept error: (%d) %s\n", (int)errno, strerror(errno) ); 34 42 } 35 43 36 printf("New connection %d, waiting for requests\n", fd);44 if( options.log ) printf("=== New connection %d, waiting for requests ===\n", fd); 37 45 REQUEST: 38 46 for() { … … 45 53 size_t len = options.socket.buflen; 46 54 char buffer[len]; 47 printf("Reading request\n");48 [code, closed, file, name_size] = http_read(fd, buffer, len );55 if( options.log ) printf("=== Reading request ===\n"); 56 [code, closed, file, name_size] = http_read(fd, buffer, len, &this.cancel); 49 57 50 58 // if we are done, break out of the loop 51 59 if( closed ) { 52 printf("Connection closed\n"); 60 if( options.log ) printf("=== Connection closed ===\n"); 61 close(fd); 53 62 continue CONNECTION; 54 63 } … … 56 65 // If this wasn't a request retrun 400 57 66 if( code != OK200 ) { 58 printf(" Invalid Request : %d\n", code_val(code));67 printf("=== Invalid Request : %d ===\n", code_val(code)); 59 68 answer_error(fd, code); 60 69 continue REQUEST; 61 70 } 62 71 63 printf("Request for file %.*s\n", (int)name_size, file); 72 if(0 == strncmp(file, "plaintext", min(name_size, sizeof("plaintext") ))) { 73 if( options.log ) printf("=== Request for /plaintext ===\n"); 74 75 char text[] = "Hello, World!\n"; 76 77 // Send the header 78 answer_plain(fd, text, sizeof(text)); 79 80 if( options.log ) printf("=== Answer sent ===\n"); 81 continue REQUEST; 82 } 83 84 if(0 == strncmp(file, "ping", min(name_size, sizeof("ping") ))) { 85 if( options.log ) printf("=== Request for /ping ===\n"); 86 87 // Send the header 88 answer_empty(fd); 89 90 if( options.log ) printf("=== Answer sent ===\n"); 91 continue REQUEST; 92 } 93 94 if( options.log ) printf("=== Request for file %.*s ===\n", (int)name_size, file); 64 95 65 96 // Get the fd from the file cache … … 70 101 // If we can't find the file, return 404 71 102 if( ans_fd < 0 ) { 72 printf(" File Not Found\n");103 printf("=== File Not Found ===\n"); 73 104 answer_error(fd, E404); 74 105 continue REQUEST; … … 81 112 sendfile( this.pipe, fd, ans_fd, count); 82 113 83 printf("File sent\n");114 if( options.log ) printf("=== Answer sent ===\n"); 84 115 } 85 116 }
Note: See TracChangeset
for help on using the changeset viewer.