mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-18 03:13:55 +00:00
Support size limit
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user