Changes in benchmark/io/http/protocol.cfa [e54d0c3:197df9b]
- File:
-
- 1 edited
-
benchmark/io/http/protocol.cfa (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/http/protocol.cfa
re54d0c3 r197df9b 5 5 #include <fcntl.h> 6 6 } 7 8 #define xstr(s) str(s) 9 #define str(s) #s 7 10 8 11 #include <fstream.hfa> … … 21 24 22 25 #define PLAINTEXT_1WRITE 26 #define PLAINTEXT_MEMCPY 23 27 #define PLAINTEXT_NOCOPY 24 28 … … 85 89 #if defined(PLAINTEXT_NOCOPY) 86 90 int answer_plaintext( int fd ) { 87 return answer(fd, http_msgs[OK200_PlainText]->msg, http_msgs[OK200_PlainText]->len + 1); // +1 cause snprintf doesn't count nullterminator 91 return answer(fd, http_msgs[OK200_PlainText]->msg, http_msgs[OK200_PlainText]->len); // +1 cause snprintf doesn't count nullterminator 92 } 93 #elif defined(PLAINTEXT_MEMCPY) 94 #define TEXTSIZE 15 95 int answer_plaintext( int fd ) { 96 char text[] = "Hello, World!\n\n"; 97 char ts[] = xstr(TEXTSIZE) " \n\n"; 98 _Static_assert(sizeof(text) - 1 == TEXTSIZE); 99 char buffer[512 + TEXTSIZE]; 100 char * it = buffer; 101 memcpy(it, http_msgs[OK200]->msg, http_msgs[OK200]->len); 102 it += http_msgs[OK200]->len; 103 int len = http_msgs[OK200]->len; 104 memcpy(it, ts, sizeof(ts) - 1); 105 it += sizeof(ts) - 1; 106 len += sizeof(ts) - 1; 107 memcpy(it, text, TEXTSIZE); 108 return answer(fd, buffer, len + TEXTSIZE); 88 109 } 89 110 #elif defined(PLAINTEXT_1WRITE) 90 111 int answer_plaintext( int fd ) { 91 char text[] = "Hello, World!\n ";112 char text[] = "Hello, World!\n\n"; 92 113 char buffer[512 + sizeof(text)]; 93 114 char * it = buffer; … … 103 124 #else 104 125 int answer_plaintext( int fd ) { 105 char text[] = "Hello, World!\n ";126 char text[] = "Hello, World!\n\n"; 106 127 int ret = answer_header(fd, sizeof(text)); 107 128 if( ret < 0 ) return ret; … … 193 214 194 215 const char * original_http_msgs[] = { 195 "HTTP/1.1 200 OK\nServer: Htt oForall\nDate: %s \nContent-Type: text/plain\nContent-Length: ",196 "HTTP/1.1 200 OK\nServer: Htt oForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 15\n\nHello, World!\n",197 "HTTP/1.1 400 Bad Request\nServer: Htt oForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",198 "HTTP/1.1 404 Not Found\nServer: Htt oForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",199 "HTTP/1.1 405 Method Not Allowed\nServer: Htt oForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",200 "HTTP/1.1 408 Request Timeout\nServer: Htt oForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",201 "HTTP/1.1 413 Payload Too Large\nServer: Htt oForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",202 "HTTP/1.1 414 URI Too Long\nServer: Htt oForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",216 "HTTP/1.1 200 OK\nServer: HttpForall\nDate: %s \nContent-Type: text/plain\nContent-Length: ", 217 "HTTP/1.1 200 OK\nServer: HttpForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 15\n\nHello, World!\n\n", 218 "HTTP/1.1 400 Bad Request\nServer: HttpForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n", 219 "HTTP/1.1 404 Not Found\nServer: HttpForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n", 220 "HTTP/1.1 405 Method Not Allowed\nServer: HttpForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n", 221 "HTTP/1.1 408 Request Timeout\nServer: HttpForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n", 222 "HTTP/1.1 413 Payload Too Large\nServer: HttpForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n", 223 "HTTP/1.1 414 URI Too Long\nServer: HttpForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n", 203 224 }; 204 225 … … 230 251 Time now = timeHiRes(); 231 252 strftime( buff, 100, "%a, %d %b %Y %H:%M:%S %Z", now ); 232 sout | "Updated date to '" | buff | "'";253 if( options.log ) sout | "Updated date to '" | buff | "'"; 233 254 234 255 for(i; KNOWN_CODES) { … … 243 264 this.idx = (this.idx + 1) % 2; 244 265 245 sout | "Date thread sleeping";266 if( options.log ) sout | "Date thread sleeping"; 246 267 247 268 sleep(1`s);
Note:
See TracChangeset
for help on using the changeset viewer.