| 40 | } |
| 41 | |
| 42 | static AwaitTask echoServer(AwaitEventLoop& await, const SocketDescriptor& serverSocket, SocketDescriptor& accepted) |
| 43 | { |
| 44 | char buffer[64] = {}; |
| 45 | AwaitSocketReceiveResult received; |
| 46 | |
| 47 | Result acceptResult = co_await await.accept(serverSocket, accepted); |
| 48 | if (not acceptResult) |
| 49 | { |
| 50 | co_return Result::Error("AwaitEcho server accept failed"); |
| 51 | } |
| 52 | Result receiveResult = co_await await.receive(accepted, {buffer, sizeof(buffer)}, received); |
| 53 | if (not receiveResult) |
| 54 | { |
| 55 | co_return Result::Error("AwaitEcho server receive failed"); |
| 56 | } |
| 57 | Result sendResult = co_await await.sendAll(accepted, received.data); |
| 58 | if (not sendResult) |
| 59 | { |
| 60 | co_return Result::Error("AwaitEcho server sendAll failed"); |
| 61 | } |
| 62 | |
| 63 | co_return Result(true); |
| 64 | } |
| 65 | |
| 66 | static AwaitTask echoClient(AwaitEventLoop& await, const SocketDescriptor& client, SocketIPAddress address, |
| 67 | Span<char> replyBuffer, AwaitSocketReceiveResult& reply) |