Skip to content

Commit

Permalink
posixL Support truncation in unix sockets readSome
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennisbonke committed Feb 18, 2024
1 parent ec3815d commit 15aeb4e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions posix/subsystem/src/un-socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ struct OpenFile : File {
while(_recvQueue.empty())
co_await _statusBell.async_wait();

// TODO: Truncate packets (for SOCK_DGRAM) here.
auto packet = &_recvQueue.front();
assert(!packet->offset);
assert(packet->files.empty());
auto size = packet->buffer.size();
assert(max_length >= size);
memcpy(data, packet->buffer.data(), size);
_recvQueue.pop_front();
co_return size;

auto chunk = std::min(packet->buffer.size() - packet->offset, max_length);
memcpy(data, packet->buffer.data() + packet->offset, chunk);
packet->offset += chunk;
if(packet->offset == packet->buffer.size())
_recvQueue.pop_front();
co_return chunk;
}

async::result<frg::expected<Error, size_t>>
Expand Down

0 comments on commit 15aeb4e

Please sign in to comment.