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

Function datagramClient

Examples/AwaitDatagramPing/AwaitDatagramPing.cpp:65–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65static 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
86static AwaitTask datagramConversation(AwaitEventLoop& await, const SocketDescriptor& server,
87 const SocketDescriptor& client, SocketIPAddress serverAddress,

Callers 1

datagramConversationFunction · 0.85

Calls 6

sendToMethod · 0.80
receiveFromMethod · 0.80
ErrorEnum · 0.50
ResultClass · 0.50
dataMethod · 0.45
sizeInBytesMethod · 0.45

Tested by

no test coverage detected