| 63 | } |
| 64 | |
| 65 | static AwaitTask datagramClient(AwaitEventLoop& await, const SocketDescriptor& client, SocketIPAddress serverAddress, |
| 66 | Span<char> replyBuffer, AwaitSocketReceiveFromResult& reply) |
| 67 | { |
| 68 | const char request[] = "ping await udp"; |
| 69 | AwaitSocketSendResult sendResult; |
| 70 | SC_CO_TRY(co_await await.sendTo(client, serverAddress, {request, sizeof(request) - 1}, &sendResult)); |
| 71 | if (sendResult.numBytes != sizeof(request) - 1) |
| 72 | { |
| 73 | co_return Result::Error("AwaitDatagramPing client sent a partial request"); |
| 74 | } |
| 75 | |
| 76 | SC_CO_TRY(co_await await.receiveFrom(client, replyBuffer, reply)); |
| 77 | StringView replyText({reply.data.data(), reply.data.sizeInBytes()}, false, StringEncoding::Ascii); |
| 78 | if (replyText != "pong await udp") |
| 79 | { |
| 80 | co_return Result::Error("AwaitDatagramPing client received an unexpected reply"); |
| 81 | } |
| 82 | |
| 83 | co_return Result(true); |
| 84 | } |
| 85 | |
| 86 | static AwaitTask datagramConversation(AwaitEventLoop& await, const SocketDescriptor& server, |
| 87 | const SocketDescriptor& client, SocketIPAddress serverAddress, |
no test coverage detected