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

Function echoServer

Examples/AwaitEcho/AwaitEcho.cpp:42–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40}
41
42static 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
66static AwaitTask echoClient(AwaitEventLoop& await, const SocketDescriptor& client, SocketIPAddress address,
67 Span<char> replyBuffer, AwaitSocketReceiveResult& reply)

Callers 1

echoConversationFunction · 0.85

Calls 5

sendAllMethod · 0.80
ErrorEnum · 0.50
ResultClass · 0.50
acceptMethod · 0.45
receiveMethod · 0.45

Tested by

no test coverage detected