Changes in benchmark/io/http/worker.cfa [97748ee:e235429]
- File:
-
- 1 edited
-
benchmark/io/http/worker.cfa (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/http/worker.cfa
r97748ee re235429 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);26 21 } 27 22 … … 33 28 CONNECTION: 34 29 for() { 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] ); 30 int fd = cfa_accept4( this.[sockfd, addr, addrlen, flags], 0, -1`s, 0p, 0p ); 38 31 if(fd < 0) { 39 32 if( errno == ECONNABORTED ) break; 40 if( errno == EINVAL && this.done ) break;41 33 abort( "accept error: (%d) %s\n", (int)errno, strerror(errno) ); 42 34 } 43 35 44 if( options.log ) printf("=== New connection %d, waiting for requests ===\n", fd);36 printf("New connection %d, waiting for requests\n", fd); 45 37 REQUEST: 46 38 for() { … … 53 45 size_t len = options.socket.buflen; 54 46 char buffer[len]; 55 if( options.log ) printf("=== Reading request ===\n");56 [code, closed, file, name_size] = http_read(fd, buffer, len , &this.cancel);47 printf("Reading request\n"); 48 [code, closed, file, name_size] = http_read(fd, buffer, len); 57 49 58 50 // if we are done, break out of the loop 59 51 if( closed ) { 60 if( options.log ) printf("=== Connection closed ===\n"); 61 close(fd); 52 printf("Connection closed\n"); 62 53 continue CONNECTION; 63 54 } … … 65 56 // If this wasn't a request retrun 400 66 57 if( code != OK200 ) { 67 printf(" === Invalid Request : %d ===\n", code_val(code));58 printf("Invalid Request : %d\n", code_val(code)); 68 59 answer_error(fd, code); 69 60 continue REQUEST; 70 61 } 71 62 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); 63 printf("Request for file %.*s\n", (int)name_size, file); 95 64 96 65 // Get the fd from the file cache … … 101 70 // If we can't find the file, return 404 102 71 if( ans_fd < 0 ) { 103 printf(" === File Not Found ===\n");72 printf("File Not Found\n"); 104 73 answer_error(fd, E404); 105 74 continue REQUEST; … … 112 81 sendfile( this.pipe, fd, ans_fd, count); 113 82 114 if( options.log ) printf("=== Answer sent ===\n");83 printf("File sent\n"); 115 84 } 116 85 }
Note:
See TracChangeset
for help on using the changeset viewer.