| 2 | #include "util.h" |
| 3 | |
| 4 | static void handle_connection(acl::socket_stream* conn, int len, int step) |
| 5 | { |
| 6 | char* buf = (char*) malloc(len + 1), *ptr; |
| 7 | int i = 0, ret; |
| 8 | |
| 9 | len = (len / step) * step; |
| 10 | if (len == 0) |
| 11 | { |
| 12 | printf("len: %d too small, step: %d\r\n", len, step); |
| 13 | return; |
| 14 | } |
| 15 | |
| 16 | struct timeval begin; |
| 17 | gettimeofday(&begin, NULL); |
| 18 | |
| 19 | while (true) |
| 20 | { |
| 21 | ptr = buf; |
| 22 | for (int j = 0; j < len; j += step) |
| 23 | { |
| 24 | ret = conn->read(ptr, step, true); |
| 25 | if (ret == -1) |
| 26 | { |
| 27 | printf("readline from client over!\r\n"); |
| 28 | goto END; |
| 29 | } |
| 30 | |
| 31 | ptr += ret; |
| 32 | } |
| 33 | |
| 34 | if (i <= 1) |
| 35 | { |
| 36 | *ptr = 0; |
| 37 | printf("buf: %s\r\n", buf); |
| 38 | } |
| 39 | |
| 40 | if (conn->write(buf, len) == -1) |
| 41 | { |
| 42 | printf("write to client error\r\n"); |
| 43 | break; |
| 44 | } |
| 45 | |
| 46 | buf[0] = 0; |
| 47 | i++; |
| 48 | } |
| 49 | |
| 50 | END: |
| 51 | free(buf); |
| 52 | |
| 53 | struct timeval end; |
| 54 | gettimeofday(&end, NULL); |
| 55 | |
| 56 | double n = util::stamp_sub(&end, &begin); |
| 57 | printf("total get: %d, spent: %0.2f ms, speed: %0.2f\r\n", |
| 58 | i, n, (i * 1000) /(n > 0 ? n : 1)); |
| 59 | } |
| 60 | |
| 61 | static void usage(const char* procname) |