| 79 | } |
| 80 | |
| 81 | static AwaitTask lineClient(AwaitEventLoop& await, const SocketDescriptor& client, SocketIPAddress address, |
| 82 | Span<char> valueBuffer, AwaitSocketReceiveLineResult& valueLine, Span<char> doneBuffer, |
| 83 | AwaitSocketReceiveLineResult& doneLine) |
| 84 | { |
| 85 | constexpr char request[] = "READ temperature\r\n"; |
| 86 | constexpr char expectedValue[] = "VALUE temperature=23.5C"; |
| 87 | constexpr char ack[] = "ACK temperature\r\n"; |
| 88 | constexpr char expectedDone[] = "DONE"; |
| 89 | |
| 90 | SC_CO_TRY(co_await await.connect(client, address)); |
| 91 | SC_CO_TRY(co_await await.sendAll(client, {request, sizeof(request) - 1})); |
| 92 | SC_CO_TRY(co_await await.receiveLine(client, valueBuffer, valueLine)); |
| 93 | if (not valueLine.lineComplete or valueLine.disconnected or |
| 94 | not equalsAscii(valueLine.line, {expectedValue, sizeof(expectedValue) - 1})) |
| 95 | { |
| 96 | co_return Result::Error("AwaitLineProtocol client received unexpected value"); |
| 97 | } |
| 98 | |
| 99 | SC_CO_TRY(co_await await.sendAll(client, {ack, sizeof(ack) - 1})); |
| 100 | SC_CO_TRY(co_await await.receiveLine(client, doneBuffer, doneLine)); |
| 101 | if (not doneLine.lineComplete or doneLine.disconnected or |
| 102 | not equalsAscii(doneLine.line, {expectedDone, sizeof(expectedDone) - 1})) |
| 103 | { |
| 104 | co_return Result::Error("AwaitLineProtocol client received unexpected completion"); |
| 105 | } |
| 106 | |
| 107 | co_return Result(true); |
| 108 | } |
| 109 | |
| 110 | static AwaitTask lineProtocolConversation(AwaitEventLoop& await, const SocketDescriptor& serverSocket, |
| 111 | const SocketDescriptor& client, SocketIPAddress address, |
no test coverage detected