| 28 | } |
| 29 | |
| 30 | void echo(void *arg) |
| 31 | { |
| 32 | int ret; |
| 33 | int *p = (int *)arg; |
| 34 | int clt_fd = *p; |
| 35 | delete p; |
| 36 | char buf[64 * 1024]; |
| 37 | while (true) { |
| 38 | ret = mt_recv(clt_fd, (void *)buf, 64 * 1024, 0, -1); |
| 39 | if (ret < 0) { |
| 40 | printf("recv from client error\n"); |
| 41 | break; |
| 42 | } |
| 43 | ret = mt_send(clt_fd, (void *)buf, ret, 0, 1000); |
| 44 | if (ret < 0) { |
| 45 | //printf("send data to client error\n"); |
| 46 | break; |
| 47 | } |
| 48 | } |
| 49 | close(clt_fd); |
| 50 | } |
| 51 | |
| 52 | int echo_server() |
| 53 | { |