• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Razakhel / RaZ / 18244960134

04 Oct 2025 01:16PM UTC coverage: 73.618% (-0.05%) from 73.672%
18244960134

push

github

Razakhel
[Network/TcpClient] Separated the send and readback operations

- TcpClient::send() now doesn't return anything; receive() can be called afterward

- Added a method to recover the byte count to be received

- Added move operations for TcpServer

5 of 16 new or added lines in 2 files covered. (31.25%)

8349 of 11341 relevant lines covered (73.62%)

1743.3 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/RaZ/Network/TcpClient.cpp
1
#include "RaZ/Network/TcpClient.hpp"
2
#include "RaZ/Utils/Logger.hpp"
3

4
#include "asio/connect.hpp"
5
#include "asio/ip/tcp.hpp"
6
#include "asio/write.hpp"
7

8
namespace Raz {
9

10
struct TcpClient::Impl {
11
  Impl() : socket(context), resolver(context) {}
×
12

13
  asio::io_context context;
14
  asio::ip::tcp::socket socket;
15
  asio::ip::tcp::resolver resolver;
16
};
17

18
TcpClient::TcpClient() : m_impl{ std::make_unique<Impl>() } {}
×
19

20
void TcpClient::connect(const std::string& host, unsigned short port) {
×
21
  Logger::debug("[TcpClient] Connecting to {}:{}...", host, port);
×
22

23
  asio::error_code error;
×
24
  asio::connect(m_impl->socket, m_impl->resolver.resolve(host, std::to_string(port)), error);
×
25

26
  if (error)
×
27
    throw std::invalid_argument(std::format("[TcpClient] Failed to connect to {}:{}: {}", host, port, error.message()));
×
28

29
  Logger::debug("[TcpClient] Connected");
×
30
}
×
31

NEW
32
void TcpClient::send(const std::string& request) {
×
33
  Logger::debug("[TcpClient] Sending '{}'...", request);
×
34

NEW
35
  asio::error_code error;
×
NEW
36
  asio::write(m_impl->socket, asio::buffer(request), error);
×
37

NEW
38
  if (error)
×
NEW
39
    throw std::runtime_error(std::format("[TcpClient] Failed to send request: {}", error.message()));
×
NEW
40
}
×
41

NEW
42
std::size_t TcpClient::recoverAvailableByteCount() {
×
NEW
43
  asio::detail::io_control::bytes_readable command(true);
×
NEW
44
  m_impl->socket.io_control(command);
×
NEW
45
  return command.get();
×
46
}
47

NEW
48
std::string TcpClient::receive() {
×
49
  std::array<char, 1024> buffer {};
×
50
  const size_t length = m_impl->socket.read_some(asio::buffer(buffer));
×
51
  return std::string(buffer.data(), length);
×
52
}
53

54
void TcpClient::close() {
×
55
  Logger::debug("[TcpClient] Closing...");
×
56
  m_impl->socket.shutdown(asio::socket_base::shutdown_both);
×
57
  m_impl->socket.close();
×
58
  Logger::debug("[TcpClient] Closed");
×
59
}
×
60

61
TcpClient::~TcpClient() = default;
×
62

63
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc