MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / lineClient

Function lineClient

Examples/AwaitLineProtocol/AwaitLineProtocol.cpp:81–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79}
80
81static 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
110static AwaitTask lineProtocolConversation(AwaitEventLoop& await, const SocketDescriptor& serverSocket,
111 const SocketDescriptor& client, SocketIPAddress address,

Callers 1

lineProtocolConversationFunction · 0.85

Calls 6

equalsAsciiFunction · 0.85
sendAllMethod · 0.80
receiveLineMethod · 0.80
ErrorEnum · 0.50
ResultClass · 0.50
connectMethod · 0.45

Tested by

no test coverage detected