| 5 | static int __len = 1024; |
| 6 | |
| 7 | static void handle_connection(acl::socket_stream& conn) |
| 8 | { |
| 9 | acl::string wbuf(__len + 1); |
| 10 | char* buf = (char*) malloc(__len + 1); |
| 11 | |
| 12 | int i; |
| 13 | |
| 14 | for (i = 0; i < __len; i++) |
| 15 | wbuf += 'X'; |
| 16 | |
| 17 | struct timeval begin; |
| 18 | gettimeofday(&begin, NULL); |
| 19 | |
| 20 | for (i = 0; i < __max; i++) |
| 21 | { |
| 22 | if (conn.write(wbuf) == -1) |
| 23 | { |
| 24 | printf("write to server error\r\n"); |
| 25 | break; |
| 26 | } |
| 27 | |
| 28 | if (conn.read(buf, __len, true) == -1) |
| 29 | { |
| 30 | printf("readline from server error\r\n"); |
| 31 | break; |
| 32 | } |
| 33 | |
| 34 | if (i <= 1) |
| 35 | { |
| 36 | buf[__len] = 0; |
| 37 | printf("buf: %s\r\n", buf); |
| 38 | } |
| 39 | |
| 40 | if (i % 1000 == 0) |
| 41 | { |
| 42 | char tmp[64]; |
| 43 | snprintf(tmp, sizeof(tmp), "total: %d, curr: %d, len: %d", |
| 44 | __max, i, __len); |
| 45 | ACL_METER_TIME(tmp); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | free(buf); |
| 50 | |
| 51 | struct timeval end; |
| 52 | gettimeofday(&end, NULL); |
| 53 | |
| 54 | double n = util::stamp_sub(&end, &begin); |
| 55 | printf("total get: %d, spent: %0.2f ms, speed: %0.2f\r\n", |
| 56 | __max, n, (i * 1000) /(n > 0 ? n : 1)); |
| 57 | } |
| 58 | |
| 59 | static void usage(const char* procname) |
| 60 | { |