| 2 | #include "util.h" |
| 3 | |
| 4 | static void handle_connection(acl::socket_stream* conn) |
| 5 | { |
| 6 | acl::string buf; |
| 7 | int i = 0; |
| 8 | |
| 9 | struct timeval begin; |
| 10 | gettimeofday(&begin, NULL); |
| 11 | |
| 12 | while (true) |
| 13 | { |
| 14 | if (conn->gets(buf, false) == false) |
| 15 | { |
| 16 | printf("readline from client over!\r\n"); |
| 17 | break; |
| 18 | } |
| 19 | if (conn->write(buf) == -1) |
| 20 | { |
| 21 | printf("write to client error\r\n"); |
| 22 | break; |
| 23 | } |
| 24 | |
| 25 | if (i % 1000 == 0) |
| 26 | printf("read count: %d, readline: %s", i, buf.c_str()); |
| 27 | i++; |
| 28 | } |
| 29 | |
| 30 | struct timeval end; |
| 31 | gettimeofday(&end, NULL); |
| 32 | |
| 33 | double n = util::stamp_sub(&end, &begin); |
| 34 | printf("total get: %d, spent: %0.2f ms, speed: %0.2f\r\n", |
| 35 | i, n, (i * 1000) /(n > 0 ? n : 1)); |
| 36 | } |
| 37 | |
| 38 | static void* thread_read(void* ctx) |
| 39 | { |