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

Razakhel / RaZ / 18434098585

11 Oct 2025 07:45PM UTC coverage: 73.601% (-0.02%) from 73.618%
18434098585

push

github

Razakhel
[Network/TcpClient] Added isConnected()

- Renamed close() to disconnect()

- Getting a "connection reset" error on server read closes the connection

2 of 10 new or added lines in 3 files covered. (20.0%)

1 existing line in 1 file now uncovered.

8350 of 11345 relevant lines covered (73.6%)

1742.68 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

NEW
20
bool TcpClient::isConnected() const {
×
NEW
21
  return m_impl->socket.is_open();
×
22
}
23

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

27
  asio::error_code error;
×
28
  asio::connect(m_impl->socket, m_impl->resolver.resolve(host, std::to_string(port)), error);
×
29

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

33
  Logger::debug("[TcpClient] Connected");
×
34
}
×
35

36
void TcpClient::send(const std::string& data) {
×
37
  Logger::debug("[TcpClient] Sending '{}'...", data);
×
38

39
  asio::error_code error;
×
40
  asio::write(m_impl->socket, asio::buffer(data), error);
×
41

42
  if (error)
×
43
    throw std::runtime_error(std::format("[TcpClient] Failed to send data: {}", error.message()));
×
44
}
×
45

46
std::size_t TcpClient::recoverAvailableByteCount() {
×
47
  asio::detail::io_control::bytes_readable command(true);
×
48
  m_impl->socket.io_control(command);
×
49
  return command.get();
×
50
}
51

52
std::string TcpClient::receive() {
×
53
  std::array<char, 1024> buffer {};
×
54
  const size_t length = m_impl->socket.read_some(asio::buffer(buffer));
×
55
  return std::string(buffer.data(), length);
×
56
}
57

NEW
58
void TcpClient::disconnect() {
×
NEW
59
  if (!isConnected())
×
NEW
60
    return;
×
61

62
  Logger::debug("[TcpClient] Closing...");
×
63
  m_impl->socket.shutdown(asio::socket_base::shutdown_both);
×
64
  m_impl->socket.close();
×
65
  Logger::debug("[TcpClient] Closed");
×
66
}
67

68
TcpClient::~TcpClient() = default;
×
69

70
}
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