Changeset 2caed18 for benchmark/io
- Timestamp:
- Feb 24, 2021, 1:41:19 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:
- 187fdb8
- Parents:
- b664af2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/http/protocol.cfa
rb664af2 r2caed18 20 20 #include "options.hfa" 21 21 22 const char * volatile date = 0p; 23 24 const char * http_msgs[] = { 25 "HTTP/1.1 200 OK\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: %zu \n\n", 26 "HTTP/1.1 400 Bad Request\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n", 27 "HTTP/1.1 404 Not Found\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n", 28 "HTTP/1.1 405 Method Not Allowed\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n", 29 "HTTP/1.1 408 Request Timeout\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n", 30 "HTTP/1.1 413 Payload Too Large\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n", 31 "HTTP/1.1 414 URI Too Long\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n", 32 }; 22 struct https_msg_str { 23 char msg[512]; 24 size_t len; 25 }; 26 27 const https_msg_str * volatile http_msgs[KNOWN_CODES] = { 0 }; 33 28 34 29 _Static_assert( KNOWN_CODES == (sizeof(http_msgs ) / sizeof(http_msgs [0]))); 35 30 36 const int http_codes[ ] = {31 const int http_codes[KNOWN_CODES] = { 37 32 200, 38 33 400, … … 71 66 /* paranoid */ assert( code < KNOWN_CODES && code != OK200 ); 72 67 int idx = (int)code; 73 return answer( fd, http_msgs[idx] , strlen( http_msgs[idx] ));68 return answer( fd, http_msgs[idx]->msg, http_msgs[idx]->len ); 74 69 } 75 70 76 71 int answer_header( int fd, size_t size ) { 77 const char * fmt = http_msgs[OK200]; 78 int len = 200; 79 char buffer[len]; 80 len = snprintf(buffer, len, fmt, date, size); 72 char buffer[512]; 73 char * it = buffer; 74 memcpy(it, http_msgs[OK200]->msg, http_msgs[OK200]->len); 75 it += http_msgs[OK200]->len; 76 int len = http_msgs[OK200]->len; 77 len += snprintf(it, 512 - len, "%d \n\n", size); 81 78 return answer( fd, buffer, len ); 82 79 } … … 172 169 #include <thread.hfa> 173 170 171 const char * original_http_msgs[] = { 172 "HTTP/1.1 200 OK\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: ", 173 "HTTP/1.1 400 Bad Request\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n", 174 "HTTP/1.1 404 Not Found\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n", 175 "HTTP/1.1 405 Method Not Allowed\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n", 176 "HTTP/1.1 408 Request Timeout\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n", 177 "HTTP/1.1 413 Payload Too Large\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n", 178 "HTTP/1.1 414 URI Too Long\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n", 179 }; 180 174 181 struct date_buffer { 175 char buff[100];182 https_msg_str strs[KNOWN_CODES]; 176 183 }; 177 184 … … 184 191 ((thread&)this){ "Server Date Thread", *options.clopts.instance[0] }; 185 192 this.idx = 0; 186 memset( this.buffers[0].buff, 0, sizeof(this.buffers[0]) );187 memset( this.buffers[1].buff, 0, sizeof(this.buffers[1]) );193 memset( &this.buffers[0], 0, sizeof(this.buffers[0]) ); 194 memset( &this.buffers[1], 0, sizeof(this.buffers[1]) ); 188 195 } 189 196 … … 195 202 or else {} 196 203 204 205 char buff[100]; 197 206 Time now = getTimeNsec(); 198 199 strftime( this.buffers[this.idx].buff, 100, "%a, %d %b %Y %H:%M:%S %Z", now ); 200 201 char * next = this.buffers[this.idx].buff; 202 __atomic_exchange_n((char * volatile *)&date, next, __ATOMIC_SEQ_CST); 207 strftime( buff, 100, "%a, %d %b %Y %H:%M:%S %Z", now ); 208 209 for(i; KNOWN_CODES) { 210 size_t len = snprintf( this.buffers[this.idx].strs[i].msg, 512, original_http_msgs[i], buff ); 211 this.buffers[this.idx].strs[i].len = len; 212 } 213 214 for(i; KNOWN_CODES) { 215 https_msg_str * next = &this.buffers[this.idx].strs[i]; 216 __atomic_exchange_n((https_msg_str * volatile *)&http_msgs[i], next, __ATOMIC_SEQ_CST); 217 } 203 218 this.idx = (this.idx + 1) % 2; 204 219
Note: See TracChangeset
for help on using the changeset viewer.