Skip to content

Commit

Permalink
Temporary added zero-inflight sslclient
Browse files Browse the repository at this point in the history
  • Loading branch information
resetius committed Dec 10, 2023
1 parent 3c289ae commit 684afeb
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,46 @@ TVoidTask Client(TPoller& poller, TSocket socket) {
co_return;
}

template<typename TPoller, typename TSocket>
TVoidTask SslClient(TPoller& poller, TSocket socket) {
using TFileHandle = typename TPoller::TFileHandle;
TFileHandle input{0, poller}; // stdin
co_await socket.Connect();
std::cout << "Connected\n";
char buf[1024];
ssize_t size = 1;

auto reader = ClientReader(poller, socket);

TLine line;
TCommandRequest header;
header.Type = static_cast<uint32_t>(TCommandRequest::MessageType);
auto lineReader = TLineReader(input, 2*1024);
auto byteWriter = TByteWriter(socket);

try {
while ((line = co_await lineReader.Read())) {
//std::cout << "Sending " << line.Size() << " bytes: '" << line.Part1 << line.Part2 << "'\n";
//std::cout << "Sending\n";
header.Len = sizeof(header) + line.Size();
times.push(timeSource.Now());
co_await byteWriter.Write(&header, sizeof(header));
co_await byteWriter.Write(line.Part1.data(), line.Part1.size());
co_await byteWriter.Write(line.Part2.data(), line.Part2.size());

auto response = co_await TMessageReader(socket).Read();
auto t = times.front(); times.pop();
auto dt = timeSource.Now() - t;
auto commandResponse = response.template Cast<TCommandResponse>();
std::cout << "Ok, commitIndex: " << commandResponse->Index << " " << dt.count() << "\n";
}
} catch (const std::exception& ex) {
std::cout << "Exception: " << ex.what() << "\n";
}
reader.destroy();
co_return;
}

void usage(const char* prog) {
std::cerr << prog << " --node ip:port:id\n";
exit(0);
Expand Down Expand Up @@ -101,7 +141,7 @@ int main(int argc, char** argv) {
std::function<void(const char*)> sslDebugLogFunc = [](const char* s) { std::cerr << s << "\n"; };
TSslContext ctx = TSslContext::Client(sslDebugLogFunc);
TSslSocket sslSocket(std::move(socket), ctx);
Client(loop.Poller(), std::move(sslSocket));
SslClient(loop.Poller(), std::move(sslSocket));
loop.Loop();
} else {
Client(loop.Poller(), std::move(socket));
Expand Down

0 comments on commit 684afeb

Please sign in to comment.