Skip to content

Commit

Permalink
Rename TReader/TWriter -> TMessageReader/TMessageWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
resetius committed Dec 10, 2023
1 parent bad363e commit 59cd1e7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ template<typename Poller>
TVoidSuspendedTask ClientReader(Poller& poller, typename Poller::TSocket& socket) {
try {
while (true) {
auto response = co_await TReader(socket).Read();
auto response = co_await TMessageReader(socket).Read();
auto t = times.front(); times.pop();
auto dt = timeSource.Now() - t;
auto commandResponse = response.template Cast<TCommandResponse>();
Expand Down
8 changes: 4 additions & 4 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "messages.h"

template<typename TSocket>
NNet::TValueTask<void> TWriter<TSocket>::Write(TMessageHolder<TMessage> message) {
NNet::TValueTask<void> TMessageWriter<TSocket>::Write(TMessageHolder<TMessage> message) {
co_await NNet::TByteWriter(Socket).Write(message.Mes, message->Len);

auto payload = std::move(message.Payload);
Expand All @@ -21,7 +21,7 @@ NNet::TValueTask<void> TWriter<TSocket>::Write(TMessageHolder<TMessage> message)
}

template<typename TSocket>
NNet::TValueTask<TMessageHolder<TMessage>> TReader<TSocket>::Read() {
NNet::TValueTask<TMessageHolder<TMessage>> TMessageReader<TSocket>::Read() {
decltype(TMessage::Type) type;
decltype(TMessage::Len) len;
auto s = co_await Socket.ReadSome(&type, sizeof(type));
Expand Down Expand Up @@ -71,7 +71,7 @@ NNet::TVoidSuspendedTask TNode<TPoller>::DoDrain() {
while (!Messages.empty()) {
auto tosend = std::move(Messages); Messages.clear();
for (auto&& m : tosend) {
co_await TWriter(Socket).Write(std::move(m));
co_await TMessageWriter(Socket).Write(std::move(m));
}
}
} catch (const std::exception& ex) {
Expand Down Expand Up @@ -121,7 +121,7 @@ NNet::TVoidTask TRaftServer<TPoller>::InboundConnection(typename TPoller::TSocke
);
Nodes.insert(client);
while (true) {
auto mes = co_await TReader(client->Sock()).Read();
auto mes = co_await TMessageReader(client->Sock()).Read();
// std::cout << "Got message " << mes->Type << "\n";
Raft->Process(TimeSource->Now(), std::move(mes), client);
Raft->ProcessTimeout(TimeSource->Now());
Expand Down
8 changes: 4 additions & 4 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#include "raft.h"

template<typename TSocket>
class TReader {
class TMessageReader {
public:
TReader(TSocket& socket)
TMessageReader(TSocket& socket)
: Socket(socket)
{ }

Expand All @@ -27,9 +27,9 @@ class TReader {
};

template<typename TSocket>
class TWriter {
class TMessageWriter {
public:
TWriter(TSocket& socket)
TMessageWriter(TSocket& socket)
: Socket(socket)
{ }

Expand Down
8 changes: 4 additions & 4 deletions test/test_read_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ void test_read_write(void**) {
NNet::TVoidSuspendedTask h1 = [](NNet::TSocket& client, TMessageHolder<TLogEntry> mes) -> NNet::TVoidSuspendedTask
{
co_await client.Connect();
co_await TWriter(client).Write(std::move(mes));
co_await TMessageWriter(client).Write(std::move(mes));
co_return;
}(client, mes);

TMessageHolder<TMessage> received;
NNet::TVoidSuspendedTask h2 = [](NNet::TSocket& server, TMessageHolder<TMessage>& received) -> NNet::TVoidSuspendedTask
{
auto client = std::move(co_await server.Accept());
received = co_await TReader(client).Read();
received = co_await TMessageReader(client).Read();
co_return;
}(socket, received);

Expand Down Expand Up @@ -88,15 +88,15 @@ void test_read_write_payload(void**) {
NNet::TVoidSuspendedTask h1 = [](NNet::TSocket& client, TMessageHolder<TMessage> mes) -> NNet::TVoidSuspendedTask
{
co_await client.Connect();
co_await TWriter(client).Write(std::move(mes));
co_await TMessageWriter(client).Write(std::move(mes));
co_return;
}(client, mes);

TMessageHolder<TMessage> received;
NNet::TVoidSuspendedTask h2 = [](NNet::TSocket& server, TMessageHolder<TMessage>& received) -> NNet::TVoidSuspendedTask
{
auto client = std::move(co_await server.Accept());
received = co_await TReader(client).Read();
received = co_await TMessageReader(client).Read();
co_return;
}(socket, received);

Expand Down

0 comments on commit 59cd1e7

Please sign in to comment.