Changeset ece0e80 for benchmark/io
- Timestamp:
- Jan 9, 2021, 4:27:57 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:
- 561dd26
- Parents:
- 35fd2c4
- Location:
- benchmark/io/http
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/http/main.cfa
r35fd2c4 rece0e80 114 114 options.clopts.instance = &cl; 115 115 116 init_protocol();117 116 118 117 int pipe_cnt = options.clopts.nworkers * 2; … … 131 130 { 132 131 ServerProc procs[options.clopts.nprocs]; 132 133 init_protocol(); 133 134 { 134 135 Worker workers[options.clopts.nworkers]; … … 158 159 printf("Shutting Down\n"); 159 160 } 161 162 for(i; options.clopts.nworkers) { 163 printf("Cancelling %p\n", (void*)workers[i].cancel.target); 164 cancel(workers[i].cancel); 165 } 166 167 printf("Shutting down socket\n"); 168 int ret = shutdown( server_fd, SHUT_RD ); 169 if( ret < 0 ) { abort( "shutdown error: (%d) %s\n", (int)errno, strerror(errno) ); } 170 171 //=================== 172 // Close Socket 173 printf("Closing Socket\n"); 174 ret = close( server_fd ); 175 if(ret < 0) { 176 abort( "close socket error: (%d) %s\n", (int)errno, strerror(errno) ); 177 } 160 178 } 161 179 printf("Workers Closed\n"); 180 181 deinit_protocol(); 162 182 } 163 183 … … 170 190 free(fds); 171 191 172 deinit_protocol();173 }174 175 //===================176 // Close Socket177 printf("Closing Socket\n");178 ret = close( server_fd );179 if(ret < 0) {180 abort( "close socket error: (%d) %s\n", (int)errno, strerror(errno) );181 192 } 182 193 -
benchmark/io/http/protocol.cfa
r35fd2c4 rece0e80 71 71 } 72 72 73 [HttpCode code, bool closed, * const char file, size_t len] http_read(int fd, []char buffer, size_t len ) {73 [HttpCode code, bool closed, * const char file, size_t len] http_read(int fd, []char buffer, size_t len, io_cancellation * cancel) { 74 74 char * it = buffer; 75 75 size_t count = len - 1; … … 77 77 READ: 78 78 for() { 79 int ret = cfa_read(fd, (void*)it, count, 0, -1`s, 0p, 0p);79 int ret = cfa_read(fd, (void*)it, count, 0, -1`s, cancel, 0p); 80 80 // int ret = read(fd, (void*)it, count); 81 81 if(ret == 0 ) return [OK200, true, 0, 0]; … … 148 148 149 149 void ?{}( DateFormater & this ) { 150 ((thread&)this){ *options.clopts.instance };150 ((thread&)this){ "Server Date Thread", *options.clopts.instance }; 151 151 this.idx = 0; 152 152 memset( this.buffers[0].buff, 0, sizeof(this.buffers[0]) ); … … 162 162 163 163 Time now = getTimeNsec(); 164 // Date: Wed, 17 Apr 2013 12:00:00 GMT 164 165 165 strftime( this.buffers[this.idx].buff, 100, "%a, %d %b %Y %H:%M:%S %Z", now ); 166 printf("Changing date to %s\n", this.buffers[this.idx].buff);167 166 168 167 char * next = this.buffers[this.idx].buff; -
benchmark/io/http/protocol.hfa
r35fd2c4 rece0e80 1 1 #pragma once 2 3 struct io_cancellation; 2 4 3 5 enum HttpCode { … … 15 17 int answer_header( int fd, size_t size ); 16 18 17 [HttpCode code, bool closed, * const char file, size_t len] http_read(int fd, []char buffer, size_t len );19 [HttpCode code, bool closed, * const char file, size_t len] http_read(int fd, []char buffer, size_t len, io_cancellation *); 18 20 19 21 void sendfile( int pipe[2], int fd, int ans_fd, size_t count ); -
benchmark/io/http/worker.cfa
r35fd2c4 rece0e80 28 28 CONNECTION: 29 29 for() { 30 int fd = cfa_accept4( this.[sockfd, addr, addrlen, flags], 0, -1`s, 0p, 0p ); 30 printf("=== Accepting connection ===\n"); 31 int fd = cfa_accept4( this.[sockfd, addr, addrlen, flags], 0, -1`s, &this.cancel, 0p ); 31 32 if(fd < 0) { 32 33 if( errno == ECONNABORTED ) break; 34 if( errno == EINVAL ) break; 33 35 abort( "accept error: (%d) %s\n", (int)errno, strerror(errno) ); 34 36 } 35 37 36 printf(" New connection %d, waiting for requests\n", fd);38 printf("=== New connection %d, waiting for requests ===\n", fd); 37 39 REQUEST: 38 40 for() { … … 45 47 size_t len = options.socket.buflen; 46 48 char buffer[len]; 47 printf(" Reading request\n");48 [code, closed, file, name_size] = http_read(fd, buffer, len );49 printf("=== Reading request ===\n"); 50 [code, closed, file, name_size] = http_read(fd, buffer, len, &this.cancel); 49 51 50 52 // if we are done, break out of the loop 51 53 if( closed ) { 52 printf(" Connection closed\n");54 printf("=== Connection closed ===\n"); 53 55 continue CONNECTION; 54 56 } … … 56 58 // If this wasn't a request retrun 400 57 59 if( code != OK200 ) { 58 printf(" Invalid Request : %d\n", code_val(code));60 printf("=== Invalid Request : %d ===\n", code_val(code)); 59 61 answer_error(fd, code); 60 62 continue REQUEST; 61 63 } 62 64 63 printf(" Request for file %.*s\n", (int)name_size, file);65 printf("=== Request for file %.*s ===\n", (int)name_size, file); 64 66 65 67 // Get the fd from the file cache … … 70 72 // If we can't find the file, return 404 71 73 if( ans_fd < 0 ) { 72 printf(" File Not Found\n");74 printf("=== File Not Found ===\n"); 73 75 answer_error(fd, E404); 74 76 continue REQUEST; … … 81 83 sendfile( this.pipe, fd, ans_fd, count); 82 84 83 printf(" File sent\n");85 printf("=== File sent ===\n"); 84 86 } 85 87 } -
benchmark/io/http/worker.hfa
r35fd2c4 rece0e80 17 17 socklen_t * addrlen; 18 18 int flags; 19 io_cancellation cancel; 19 20 }; 20 21 void ?{}( Worker & this);
Note: See TracChangeset
for help on using the changeset viewer.