diff --git a/apps/EchoClient.cpp b/apps/EchoClient.cpp index 03737953bc6de506a25c754671c16d50de271814..323de82e71f9420d19947559edd3d8e4cd400284 100644 --- a/apps/EchoClient.cpp +++ b/apps/EchoClient.cpp @@ -27,12 +27,13 @@ #include "Common.hpp" // for DIE_MSG_ERRNO, DIE_MSG, unli... #include "CountingPrivateSemaphore.hpp" // for CPS #include "Debug.hpp" // for LOGE -#include "Fiber.hpp" // for Fiber -#include "Runtime.hpp" // for Runtime -#include "Semaphore.hpp" // for Semaphore -#include "emper.hpp" // for spawn -#include "io.hpp" // for connectAndWait -#include "io/Future.hpp" // for CloseFuture, RecvFuture, Sen... +#include "Emper.hpp" +#include "Fiber.hpp" +#include "Runtime.hpp" +#include "Semaphore.hpp" +#include "emper.hpp" +#include "io.hpp" +#include "io/Future.hpp" #include "lib/math.hpp" using emper::Semaphore; @@ -101,6 +102,13 @@ struct TimeStamps { class Client { using IterationResult = std::pair<int, std::string>; + enum class ClientState { + unknown, + connecting, + sending, + receiving, + }; + size_t id; Semaphore& readySem; Semaphore& startSem; @@ -112,6 +120,8 @@ class Client { char* inBuf; char* outBuf; + ClientState state = ClientState::connecting; + public: static std::atomic<size_t> client_ids; @@ -145,6 +155,12 @@ class Client { static auto startNew(Semaphore& readySem, Semaphore& startSem, CPS& cps) -> bool; private: + void setState(ClientState newState) { + if constexpr (emper::DEBUG) { + state = newState; + } + } + [[nodiscard]] auto shouldTerminate() const -> bool { return iteration >= iterations || terminate.load(std::memory_order_relaxed); } @@ -182,6 +198,7 @@ class Client { void onCONNRESET() { LOGW("Client " << id << " reconnecting"); + setState(ClientState::connecting); closeAndForget(sock); // reconnect to try again connect(); @@ -242,6 +259,7 @@ class Client { } if constexpr (!linkedFutures) { + setState(ClientState::sending); sendFuture.submit(); if constexpr (collectTimeStamps) { @@ -252,6 +270,7 @@ class Client { break; } int32_t bytes_send = sendFuture.wait(); + setState(ClientState::receiving); if constexpr (collectTimeStamps) { timeStamps[iteration].afterSendDispatch = high_resolution_clock::now(); @@ -266,6 +285,7 @@ class Client { echoError(err, "send failed"); } } else { + setState(ClientState::unknown); recvFuture.setDependency(sendFuture); }