| 28 | } |
| 29 | |
| 30 | task<> server(uint16_t port) { |
| 31 | acceptor ac{inet_address{port}}; |
| 32 | // 限时2s,只接受一个 client |
| 33 | int sockfd = co_await timeout(ac.accept(), 2s); |
| 34 | if (sockfd >= 0) { |
| 35 | co_spawn(session(Socket{sockfd})); |
| 36 | } else { |
| 37 | log_error(-sockfd); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | task<> client(std::string_view hostname, uint16_t port) { |
| 42 | inet_address addr; |