Support size limit

This commit is contained in:
momo5502
2025-01-17 16:54:57 +01:00
parent 64179c6580
commit 7d62d1e20e
2 changed files with 4 additions and 3 deletions

View File

@@ -56,11 +56,12 @@ namespace network
return data.empty();
}
std::optional<std::string> tcp_client_socket::receive()
std::optional<std::string> tcp_client_socket::receive(const std::optional<size_t> max_size)
{
char buffer[0x2000];
const auto size = std::min(sizeof(buffer), max_size.value_or(sizeof(buffer)));
const auto result = recv(this->get_socket(), buffer, static_cast<int>(sizeof(buffer)), 0);
const auto result = recv(this->get_socket(), buffer, static_cast<int>(size), 0);
if (result > 0)
{
return std::string(buffer, result);

View File

@@ -21,7 +21,7 @@ namespace network
[[maybe_unused]] bool send(const void* data, size_t size) const;
[[maybe_unused]] bool send(std::string_view data) const;
std::optional<std::string> receive();
std::optional<std::string> receive(std::optional<size_t> max_size = std::nullopt);
std::optional<address> get_target() const;