Remove byte counters from sockets

This commit is contained in:
Patrick Nicolas
2025-11-11 21:12:01 +01:00
parent ffd5cf882a
commit efde4bf247
4 changed files with 51 additions and 53 deletions
+14 -9
View File
@@ -46,6 +46,9 @@ private:
control_socket_t control;
stream_socket_t stream;
std::atomic<uint64_t> bytes_sent_ = 0;
std::atomic<uint64_t> bytes_received_ = 0;
template <typename T>
void handshake(T address, bool tcp_only, crypto::key & headset_keypair, std::function<std::string(int fd)> pin_enter);
@@ -60,16 +63,16 @@ public:
template <typename T>
void send_control(T && packet)
{
control.send(std::forward<T>(packet));
bytes_sent_ += control.send(std::forward<T>(packet));
}
template <typename T>
void send_stream(T && packet)
{
if (stream)
stream.send(std::forward<T>(packet));
bytes_sent_ += stream.send(std::forward<T>(packet));
else
control.send(std::forward<T>(packet));
bytes_sent_ += control.send(std::forward<T>(packet));
}
template <typename T>
@@ -81,9 +84,9 @@ public:
fds[1].events = POLLIN;
fds[1].fd = control.get_fd();
while (auto packet = stream.receive_pending())
while (auto packet = stream.receive_pending(&bytes_received_))
std::visit(std::forward<T>(visitor), std::move(*packet));
while (auto packet = control.receive_pending())
while (auto packet = control.receive_pending(&bytes_received_))
std::visit(std::forward<T>(visitor), std::move(*packet));
int r = ::poll(fds, std::size(fds), timeout.count());
@@ -98,14 +101,16 @@ public:
if (fds[0].revents & POLLIN)
{
auto packet = stream.receive();
auto packet = stream.receive(&bytes_received_);
if (packet)
{
std::visit(std::forward<T>(visitor), std::move(*packet));
}
}
if (fds[1].revents & POLLIN)
{
auto packet = control.receive();
auto packet = control.receive(&bytes_received_);
if (packet)
std::visit(std::forward<T>(visitor), std::move(*packet));
}
@@ -115,11 +120,11 @@ public:
uint64_t bytes_received() const
{
return control.bytes_received() + stream.bytes_received();
return bytes_received_;
}
uint64_t bytes_sent() const
{
return control.bytes_sent() + stream.bytes_sent();
return bytes_sent_;
}
};