| 28 | std::atomic<uint64_t> total_messages(0); |
| 29 | |
| 30 | class HTTPSTraceClient : public HTTPSClient |
| 31 | { |
| 32 | public: |
| 33 | HTTPSTraceClient(const std::shared_ptr<Service>& service, std::shared_ptr<SSLContext> context, const std::string& address, int port, int messages) |
| 34 | : HTTPSClient(service, context, address, port), |
| 35 | _messages(messages) |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | void SendMessage() { SendRequestAsync(request().MakeTraceRequest("/")); } |
| 40 | |
| 41 | protected: |
| 42 | void onHandshaked() override |
| 43 | { |
| 44 | for (size_t i = _messages; i > 0; --i) |
| 45 | SendMessage(); |
| 46 | } |
| 47 | |
| 48 | void onSent(size_t sent, size_t pending) override |
| 49 | { |
| 50 | _sent += sent; |
| 51 | HTTPSClient::onSent(sent, pending); |
| 52 | } |
| 53 | |
| 54 | void onReceived(const void* buffer, size_t size) override |
| 55 | { |
| 56 | _received += size; |
| 57 | timestamp_stop = Timestamp::nano(); |
| 58 | total_bytes += size; |
| 59 | HTTPSClient::onReceived(buffer, size); |
| 60 | } |
| 61 | |
| 62 | void onReceivedResponse(const HTTPResponse& response) override |
| 63 | { |
| 64 | if (response.status() == 200) |
| 65 | ++total_messages; |
| 66 | else |
| 67 | ++total_errors; |
| 68 | SendMessage(); |
| 69 | } |
| 70 | |
| 71 | void onReceivedResponseError(const HTTPResponse& response, const std::string& error) override |
| 72 | { |
| 73 | std::cout << "Response error: " << error << std::endl; |
| 74 | ++total_errors; |
| 75 | SendMessage(); |
| 76 | } |
| 77 | |
| 78 | void onError(int error, const std::string& category, const std::string& message) override |
| 79 | { |
| 80 | std::cout << "HTTPS Trace client caught an error with code " << error << " and category '" << category << "': " << message << std::endl; |
| 81 | ++total_errors; |
| 82 | } |
| 83 | |
| 84 | private: |
| 85 | size_t _sent{0}; |
| 86 | size_t _received{0}; |
| 87 | size_t _messages{0}; |
nothing calls this directly
no outgoing calls
no test coverage detected