MCPcopy Create free account
hub / github.com/chronoxor/CppServer / EchoClient

Class EchoClient

performance/ssl_echo_client.cpp:31–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29std::atomic<uint64_t> total_messages(0);
30
31class EchoClient : public SSLClient
32{
33public:
34 EchoClient(const std::shared_ptr<Service>& service, std::shared_ptr<SSLContext> context, const std::string& address, int port, int messages)
35 : SSLClient(service, context, address, port),
36 _messages(messages)
37 {
38 }
39
40 void SendMessage() { SendAsync(message_to_send.data(), message_to_send.size()); }
41
42protected:
43 void onHandshaked() override
44 {
45 for (size_t i = _messages; i > 0; --i)
46 SendMessage();
47 }
48
49 void onSent(size_t sent, size_t pending) override
50 {
51 _sent += sent;
52 }
53
54 void onReceived(const void* buffer, size_t size) override
55 {
56 _received += size;
57 while (_received >= message_to_send.size())
58 {
59 SendMessage();
60 _received -= message_to_send.size();
61 }
62
63 timestamp_stop = Timestamp::nano();
64 total_bytes += size;
65 }
66
67 void onError(int error, const std::string& category, const std::string& message) override
68 {
69 std::cout << "SSL client caught an error with code " << error << " and category '" << category << "': " << message << std::endl;
70 ++total_errors;
71 }
72
73private:
74 size_t _sent{0};
75 size_t _received{0};
76 size_t _messages{0};
77};
78
79int main(int argc, char** argv)
80{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected