Skip to content

Commit

Permalink
posix: Support partial reads in unix sockets readSome
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennisbonke committed Feb 21, 2024
1 parent 3fa00d2 commit d81c24f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions posix/subsystem/src/un-socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,14 @@ struct OpenFile : File {

// 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 d81c24f

Please sign in to comment.