| 19 | } |
| 20 | |
| 21 | void echo_client(ACL_VSTREAM *cstream, int rw_timeout, int echo_data) |
| 22 | { |
| 23 | char buf[8192]; |
| 24 | int ret, count = 0, ecnt = 0; |
| 25 | |
| 26 | #define SOCK ACL_VSTREAM_SOCK |
| 27 | |
| 28 | if (rw_timeout > 0) { |
| 29 | set_timeout(cstream, rw_timeout); |
| 30 | } |
| 31 | |
| 32 | while (1) { |
| 33 | time_t begin = time(NULL); |
| 34 | ret = acl_vstream_read(cstream, buf, sizeof(buf) - 1); |
| 35 | time_t end = time(NULL); |
| 36 | |
| 37 | if (ret == ACL_VSTREAM_EOF) { |
| 38 | if (errno == EAGAIN && ++ecnt <= 3) { |
| 39 | printf("EAGAIN, try again, fd: %d, cost=%ld\r\n", |
| 40 | SOCK(cstream), end - begin); |
| 41 | continue; |
| 42 | } |
| 43 | printf("read error: %s, fd: %d, count: %d, timeout count=%d\r\n", |
| 44 | acl_last_serror(), SOCK(cstream), count, ecnt); |
| 45 | break; |
| 46 | } |
| 47 | buf[ret] = 0; |
| 48 | //printf("gets line: %s", buf); |
| 49 | |
| 50 | #if 1 |
| 51 | if (rw_timeout >= 5) { |
| 52 | rw_timeout = 2; |
| 53 | set_timeout(cstream, rw_timeout); |
| 54 | printf(">>reset read timeout to %d\r\n", rw_timeout); |
| 55 | } |
| 56 | #endif |
| 57 | |
| 58 | if (!echo_data) { |
| 59 | count++; |
| 60 | continue; |
| 61 | } |
| 62 | |
| 63 | if (acl_vstream_writen(cstream, buf, ret) == ACL_VSTREAM_EOF) { |
| 64 | printf("write error, fd: %d\r\n", SOCK(cstream)); |
| 65 | break; |
| 66 | } |
| 67 | |
| 68 | count++; |
| 69 | //printf("count=%d\n", count); |
| 70 | } |
| 71 | |
| 72 | acl_vstream_close(cstream); |
| 73 | } |
no test coverage detected
searching dependent graphs…